Interface FileHandle

All Superinterfaces:
Comparable<FileHandle>
All Known Subinterfaces:
ExportInfoFileHandle

public interface FileHandle extends Comparable<FileHandle>
Interface for file handles provided by a FileSystem.
Since:
5.0.413
  • Method Details

    • exists

      boolean exists()
      Indicates, whether the file referred to with the handle exists.
      Returns:
      true, iff the file exists.
      Since:
      5.0.413
    • getType

      @NotNull @NotNull FileType getType()
      Returns the type of the file handle.
      Returns:
      The file's type.
      Since:
      5.0.413
    • isFile

      boolean isFile()
      Shortcut for getType() == FILE
      Since:
      5.0.413
    • isDirectory

      boolean isDirectory()
      Shortcut for getType() == DIR
      Since:
      5.0.413
    • listFiles

      @NotNull @NotNull List<FileHandle> listFiles() throws IOException
      Returns the files in the directory referenced by the handle.
      Returns:
      A list of file handles.
      Throws:
      IOException - If an error occurred accessing the file.
      de.espirit.firstspirit.server.io.InvalidOperationOnTypeException - If the file is no directory.
      Since:
      5.0.413
    • mkDirs

      void mkDirs() throws IOException
      Create all necessary directories up to this one.

      Note: The creation process may partially succeed before failing!

      Throws:
      IOException - If creating directories failed.
      de.espirit.firstspirit.server.io.InvalidOperationOnTypeException - If the file is no directory.
      Since:
      5.0.413
    • load

      @NotNull @NotNull InputStream load() throws IOException
      If isFile() returns true, returns a stream handle on the file's content.
      Returns:
      An InputStream or null.
      Throws:
      IOException - If an error occured accessing the file.
      de.espirit.firstspirit.server.io.InvalidOperationOnTypeException - If the file is no file.
      Since:
      5.0.413
    • save

      void save(InputStream content) throws IOException
      If isFile() returns true, saves the stream-given content to the file.

      Note: The given InputStream will be closed when finished!

      Parameters:
      content - The content providing stream.
      Throws:
      IOException - If an error occurred writing the file.
      de.espirit.firstspirit.server.io.InvalidOperationOnTypeException - If the file is no file.
      Since:
      5.0.413
    • append

      void append(InputStream content) throws IOException
      If isFile() returns true, appends the stream-given content to the file.

      Note: closes given InputStream when finished!

      Parameters:
      content - The content providing stream.
      Throws:
      IOException - If an error occurred writing the file.
      de.espirit.firstspirit.server.io.InvalidOperationOnTypeException - If the file is no file.
      Since:
      5.0.413
    • getOutputStream

      @NotNull @NotNull OutputStream getOutputStream() throws IOException
      Returns an OutputStream to store content to the file. Short form for getOutputStream(false)
      Attention: ensure to close the stream!
      Returns:
      an OutputStream to store content to the file.
      Throws:
      IOException - If an error occurred writing the file.
      de.espirit.firstspirit.server.io.InvalidOperationOnTypeException - If this handle is no file or writing is not allowed.
      Since:
      5.0.413
      See Also:
    • getOutputStream

      @NotNull @NotNull OutputStream getOutputStream(boolean append) throws IOException
      Provides an OutputStream to store content to the file. The stream may be opened anew or for appending content. Attention: ensure to close the stream after usage!
      Parameters:
      append - If true, will open the stream for appending to existing content.
      Returns:
      An OutputStream for storing content to the related file.
      Throws:
      IOException - If an error occured writing the file.
      de.espirit.firstspirit.server.io.InvalidOperationOnTypeException - If this handle is no file or writing is not allowed.
      Since:
      5.2.2
    • getName

      String getName()
      The name of the file (without path), or the last part of the name its a directory
      Since:
      5.0.413
    • getPath

      String getPath()
      The path of the file (including file name if getType() delivers FileType.FILE).
      Path elements are seperated with slashes "/".
      Since:
      5.0.413
    • getSize

      long getSize()
      The size of the file in bytes, delivers 0 if getType() is not FileType.FILE
      Since:
      5.0.413
    • hasCrc

      boolean hasCrc()
      Delivers true if getType() == FileType.FILE) and the crc checksum could be calculated (which may not work for some FileSystem's)
      Since:
      5.0.413
    • getCrc

      long getCrc() throws IOException
      Delivers the crc checksum if hasCrc() returns true, else returns 0
      Throws:
      IOException
      Since:
      5.0.413
    • delete

      void delete() throws IOException
      Deletes this file or (recursiv) this directory
      Throws:
      IOException
      Since:
      5.0.413
    • rename

      void rename(String newName) throws IOException
      Rename this file or directory.
      The provided name must not contain any slashes!
      Throws:
      IOException
      Since:
      5.0.413
    • swapWith

      void swapWith(String path) throws IOException
      Swap the file with the another on stored at the given path. If no file is stored at the given path, the file is being renamed.
      Parameters:
      path - The path to the file to be swapped.
      Throws:
      IOException
      Since:
      5.0.413
    • getLastModified

      long getLastModified()
      Get the last modification time of the referenced file in milliseconds.
      Returns:
      The last modification time.
      Since:
      5.0.413
    • setLastModified

      void setLastModified(long time) throws IOException
      Set the last modification time of the referenced file in milliseconds. This operation may not be supported by the underlying FileSystem and, thus, may have no effect.
      Parameters:
      time - The last modification time to set.
      Throws:
      IOException
      Since:
      5.0.413
    • getParent

      @Nullable @Nullable FileHandle getParent() throws IOException
      Get a handle on the parent file.
      Returns:
      The parent's handle or null, if there is no parent.
      Throws:
      IOException
      Since:
      5.0.413
    • getChild

      FileHandle getChild(String name) throws IOException
      Get a handle on the child with the given name.
      Parameters:
      name - The name of the child file.
      Returns:
      The handle on the child.
      Throws:
      IOException
      Since:
      5.0.413