Interface WritableMount

All Superinterfaces:
Mount

public interface WritableMount extends Mount
Represents a part of a virtual filesystem that can be mounted onto a computer using 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 Details

    • makeDirectory

      void makeDirectory(String path) throws IOException
      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

      void delete(String path) throws IOException
      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

      void rename(String source, String dest) throws IOException
      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(forRemoval=true) SeekableByteChannel openForWrite(String path) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Replaced with more the generic openFile(String, Set).
      Opens a file with a given path, and returns an SeekableByteChannel for 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(forRemoval=true) SeekableByteChannel openForAppend(String path) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Replaced with more the generic openFile(String, Set).
      Opens a file with a given path, and returns an SeekableByteChannel for 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

      default SeekableByteChannel openFile(String path, Set<OpenOption> options) throws IOException
      Opens a file with a given path, and returns an SeekableByteChannel.

      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 and MountConstants.APPEND_OPTIONS should be supported. It is recommended any valid combination of StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING and StandardOpenOption.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

      long getRemainingSpace() throws IOException
      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 the getRemainingSpace().
      Returns:
      The capacity of this mount, in bytes.
    • isReadOnly

      default boolean isReadOnly(String path) throws IOException
      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.