Interface WritableMount
- All Superinterfaces:
Mount
IComputerAccess.mount(String, Mount)
or IComputerAccess.mountWritable(String, WritableMount), that can also be written to.
Typically you will not need to implement this interface yourself, and can use the factory methods from the the main ComputerCraft API.
-
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes a directory at a given path inside the virtual file system.longGet the capacity of this mount.longGet the amount of free space on the mount, in bytes.default booleanisReadOnly(String path) Returns whether a file with a given path is read-only or not.voidmakeDirectory(String path) Creates a directory at a given path inside the virtual file system.default SeekableByteChannelopenFile(String path, Set<OpenOption> options) Opens a file with a given path, and returns anSeekableByteChannel.openForAppend(String path) Deprecated, for removal: This API element is subject to removal in a future version.openForWrite(String path) Deprecated, for removal: This API element is subject to removal in a future version.Replaced with more the genericopenFile(String, Set).voidRename a file or directory, moving it from one path to another.Methods inherited from interface dan200.computercraft.api.filesystem.Mount
exists, getAttributes, getSize, isDirectory, list, openForRead
-
Method Details
-
makeDirectory
Creates a directory at a given path inside the virtual file system.- Parameters:
path- A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms".- Throws:
IOException- If the directory already exists or could not be created.
-
delete
Deletes a directory at a given path inside the virtual file system. If the file does not exist, this method should do nothing.- Parameters:
path- A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms".- Throws:
IOException- If the file does not exist or could not be deleted.
-
rename
Rename a file or directory, moving it from one path to another.The destination path should not exist. The parent of the destination should exist and be a directory. If source and destination are the same, this method should do nothing.
- Parameters:
source- The source file or directory to move.dest- The destination path.- Throws:
IOException
-
openForWrite
Deprecated, for removal: This API element is subject to removal in a future version.Replaced with more the genericopenFile(String, Set).Opens a file with a given path, and returns anSeekableByteChannelfor writing to it.- Parameters:
path- A file path in normalised format, relative to the mount location. ie: "programs/myprogram".- Returns:
- A channel for writing to.
- Throws:
IOException- If the file could not be opened for writing.
-
openForAppend
Deprecated, for removal: This API element is subject to removal in a future version.Replaced with more the genericopenFile(String, Set).Opens a file with a given path, and returns anSeekableByteChannelfor appending to it.- Parameters:
path- A file path in normalised format, relative to the mount location. ie: "programs/myprogram".- Returns:
- A channel for writing to.
- Throws:
IOException- If the file could not be opened for writing.
-
openFile
Opens a file with a given path, and returns anSeekableByteChannel.This allows opening a file in a variety of options, much like
FileChannel.open(Path, Set, FileAttribute[]).At minimum, the option sets
MountConstants.READ_OPTIONS,MountConstants.WRITE_OPTIONSandMountConstants.APPEND_OPTIONSshould be supported. It is recommended any valid combination ofStandardOpenOption.READ,StandardOpenOption.WRITE,StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTINGandStandardOpenOption.APPENDare supported.Unsupported modes (or combinations of modes) should throw an exception with the message
"Unsupported mode".- Parameters:
path- A file path in normalised format, relative to the mount location. ie: "programs/myprogram".options- For options used for opening a file.- Returns:
- A channel for writing to.
- Throws:
IOException- If the file could not be opened for writing.
-
getRemainingSpace
Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail once it reaches zero.- Returns:
- The amount of free space, in bytes.
- Throws:
IOException- If the remaining space could not be computed.
-
getCapacity
long getCapacity()Get the capacity of this mount. This should be equal to the size of all files/directories on this mount, minus thegetRemainingSpace().- Returns:
- The capacity of this mount, in bytes.
-
isReadOnly
Returns whether a file with a given path is read-only or not.- Parameters:
path- A file path in normalised format, relative to the mount location. ie: "programs/myprograms".- Returns:
- If the file exists and is read-only.
- Throws:
IOException- If an error occurs when checking whether the file is read-only.
-
openFile(String, Set).