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.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Deletes a directory at a given path inside the virtual file system.long
Get the capacity of this mount.long
Get the amount of free space on the mount, in bytes.default boolean
isReadOnly
(String path) Returns whether a file with a given path is read-only or not.void
makeDirectory
(String path) Creates a directory at a given path inside the virtual file system.openFile
(String path, Set<OpenOption> options) Opens a file with a given path, and returns anSeekableByteChannel
.void
Rename 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
-
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_OPTIONS
andMountConstants.APPEND_OPTIONS
should be supported. It is recommended any valid combination ofStandardOpenOption.READ
,StandardOpenOption.WRITE
,StandardOpenOption.CREATE
,StandardOpenOption.TRUNCATE_EXISTING
andStandardOpenOption.APPEND
are 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.
-