Interface FileArchive

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
ZipArchive

public interface FileArchive extends Closeable
Since:
3.2.0
Author:
Joel Uckelman
  • Method Details

    • getName

      String getName()
      Gets the path to the archive file.
      Returns:
      the path as a String
    • getFile

      File getFile()
      Gets the path to the archive file.
      Returns:
      the path as a File
    • getInputStream

      InputStream getInputStream(String path) throws IOException
      Gets an InputStream to read from the given file.
      Parameters:
      path - the path to the file in the archive
      Returns:
      an InputStream containing the requested file
      Throws:
      IOException - oops
    • getOutputStream

      OutputStream getOutputStream(String path) throws IOException
      Gets an OutputStream to write to the given file.
      Parameters:
      path - the path to the file in the archive
      Returns:
      an OutputStream for the requested file
      Throws:
      IOException - oops
    • add

      void add(String path, String extPath) throws IOException
      Adds a file to the archive.
      Parameters:
      path - the internal path of the file to be added
      extPath - the external path of the file to be added
      Throws:
      IOException - oops
    • add

      void add(String path, File extPath) throws IOException
      Adds a file to the archive.
      Parameters:
      path - the internal path of the file to be added
      extPath - the external path to the file to be added
      Throws:
      IOException - oops
    • add

      void add(String path, byte[] bytes) throws IOException
      Adds the contents of a byte array to the archive.
      Parameters:
      path - the internal path of the file to be added
      bytes - the bytes to be added
      Throws:
      IOException - oops
    • add

      void add(String path, InputStream in) throws IOException
      Adds the contents of an InputStream to the archive.
      Parameters:
      path - the internal path of the file to be added
      in - the InputStream to read from
      Throws:
      IOException - oops
    • remove

      boolean remove(String path) throws IOException
      Removes a file from the archive.
      Parameters:
      path - the path to the file in the archive
      Returns:
      true if the file existed in the archive
      Throws:
      IOException - oops
    • revert

      void revert() throws IOException
      Reverts the archive to its last saved state.
      Throws:
      IOException - oops
    • flush

      void flush() throws IOException
      Forces all changes to the archive to disk.
      Throws:
      IOException - oops
    • close

      void close() throws IOException
      Closes the archive, writing all changes to disk.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - oops
    • contains

      boolean contains(String path) throws IOException
      Queries whether a file exists in the archive.
      Parameters:
      path - the path to the file in the archive
      Returns:
      true if the file exists in the archive
      Throws:
      IOException - oops
    • isClosed

      boolean isClosed()
      Queries whether the archive is closed.
      Returns:
      true if the archive is closed
    • isModified

      boolean isModified()
      Queries whether the archive has unsaved modifications.
      Returns:
      true if the archive is modified
    • getSize

      long getSize(String path) throws IOException
      Gets the size of a file in the archive, in bytes.
      Parameters:
      path - the path to the file in the archive
      Returns:
      the size of the file, in bytes
      Throws:
      FileNotFoundException - if path is not in the archive
      IOException - oops
    • getCompressedSize

      default long getCompressedSize(String path) throws IOException
      Get the compressed size of a file in the archive, in bytes. Rerurn the uncompressed size by default.
      Returns:
      the compressed size of the file, in bytes
      Throws:
      FileNotFoundException - if path is not in the archive
      IOException - oops
    • getMTime

      long getMTime(String path) throws IOException
      Gets the modification time of a file in the archive, in milliseconds since the epoch.
      Parameters:
      path - the path to the file in the archive
      Returns:
      the mtime of the file
      Throws:
      FileNotFoundException - if path is not in the archive
      IOException - oops
    • getFiles

      List<String> getFiles() throws IOException
      Gets the list of files in the archive.
      Returns:
      the list of files in the archive
      Throws:
      IOException - oops
    • getFiles

      List<String> getFiles(String root) throws IOException
      Gets the list of files under a given directory of the archive.
      Parameters:
      root - the directory
      Returns:
      the list of files under the given directory
      Throws:
      FileNotFoundException - if root is not in the archive
      IOException - oops