Interface IFileHandle

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
FilesystemHandle, ResourceHandle

public interface IFileHandle
extends Closeable
Generic handle to an IFile or File instance.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int APPEND
    Open file in append mode.
    static int READ
    Open file in read mode.
    static int WRITE
    Open file in write mode.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Close a file instance.
    boolean createFile​(boolean createHierarchy)
    Create a file.
    boolean exists()
    Check if a physical file exists.
    Object getFile()
    Get the base file object.
    int getMode()
    Get the mode (READ/WRITE/APPEND) this handle is operating for.
    Path getPath()
    Returns the java.io.File Path to the underlying file.
    String read​(int characters)
    Read characters from a file.
    String readLine()
    Read a line of data from a file.
    void write​(byte[] data)
    Write data to a file.
    void write​(String data)
    Write data to a file.
  • Field Details

  • Method Details

    • read

      String read​(int characters) throws IOException
      Read characters from a file.
      Parameters:
      characters - amount of characters to read
      Returns:
      data read from file
      Throws:
      IOException - on access errors
    • readLine

      String readLine() throws IOException
      Read a line of data from a file. Reads until a line feed is detected.
      Returns:
      single line of text
      Throws:
      IOException - on access errors
    • getPath

      Path getPath() throws IOException
      Returns the java.io.File Path to the underlying file.
      Returns:
      Path of the file
      Throws:
      IOException - on access errors
    • write

      void write​(String data) throws IOException
      Write data to a file. Uses platform default encoding to write strings to the file.
      Parameters:
      data - data to write
      Throws:
      IOException - on write errors
    • write

      void write​(byte[] data) throws IOException
      Write data to a file.
      Parameters:
      data - data to write
      Throws:
      IOException - on write errors
    • exists

      boolean exists()
      Check if a physical file exists.
      Returns:
      true when file exists
    • createFile

      boolean createFile​(boolean createHierarchy) throws IOException
      Create a file.
      Parameters:
      createHierarchy - create parent folders if they do not exist
      Returns:
      true on success
      Throws:
      Exception - on creation errors
      IOException
    • close

      void close()
      Close a file instance.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getFile

      Object getFile()
      Get the base file object. Returns an IFile or a File instance.
      Returns:
      base file object
    • getMode

      int getMode()
      Get the mode (READ/WRITE/APPEND) this handle is operating for.
      Returns:
      file mode