Interface Archiver


  • public interface Archiver
    An Archiver facades a specific archiving library, allowing for simple archiving of files and directories, and extraction of archives.
    Some archivers might use an additional Compressor to compress and decompress their respective archive files.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.io.File create​(java.lang.String archive, java.io.File destination, java.io.File source)
      Creates an archive from the given source file or directory, and saves it into the given destination.
      java.io.File create​(java.lang.String archive, java.io.File destination, java.io.File... sources)
      Creates an archive from the given source files or directories, and saves it into the given destination.
      void extract​(java.io.File archive, java.io.File destination)
      Extracts the given archive file into the given destination directory.
      void extract​(java.io.InputStream archive, java.io.File destination)
      Extracts the given archive supplied as an input stream into the given destination directory.
      java.lang.String getFilenameExtension()
      Returns the filename extension that indicates the file format this archiver handles.
      ArchiveStream stream​(java.io.File archive)
      Reads the given archive file as an ArchiveStream which is used to access individual ArchiveEntry objects within the archive without extracting the archive onto the file system.
    • Method Detail

      • create

        java.io.File create​(java.lang.String archive,
                            java.io.File destination,
                            java.io.File source)
                     throws java.io.IOException
        Creates an archive from the given source file or directory, and saves it into the given destination.
        If the source is a directory, the archive will contain all the files in that directory, but not the directory itself.
        If the archive parameter has no file extension (e.g. "archive" instead of "archive.zip"), the concrete archiver implementation should append it according to its file format (.zip, .tar, .tar.gz, ...).
        Parameters:
        archive - the name of the archive to create
        destination - the destination directory where to place the created archive
        source - the input file or directory to archive
        Returns:
        the newly created archive file
        Throws:
        java.io.IOException - propagated I/O errors by java.io
      • create

        java.io.File create​(java.lang.String archive,
                            java.io.File destination,
                            java.io.File... sources)
                     throws java.io.IOException
        Creates an archive from the given source files or directories, and saves it into the given destination.
        If the source is a directory, the archive will contain all the files in that directory, but not the directory itself.
        If the archive parameter has no file extension (e.g. "archive" instead of "archive.zip"), the concrete archiver implementation should append it according to its file format (.zip, .tar, .tar.gz, ...).
        Parameters:
        archive - the name of the archive to create
        destination - the destination directory where to place the created archive
        sources - the input files or directories to archive
        Returns:
        the newly created archive file
        Throws:
        java.io.IOException - propagated I/O errors by java.io
      • extract

        void extract​(java.io.File archive,
                     java.io.File destination)
              throws java.io.IOException
        Extracts the given archive file into the given destination directory.
        The destination is expected to be a writable directory.
        Parameters:
        archive - the archive file to extract
        destination - the directory to which to extract the files
        Throws:
        java.io.IOException - propagated I/O errors by java.io
      • extract

        void extract​(java.io.InputStream archive,
                     java.io.File destination)
              throws java.io.IOException
        Extracts the given archive supplied as an input stream into the given destination directory.
        The destination directory is expected to be a writable directory.
        Parameters:
        archive - the archive contents as a stream.
        destination - the destination directory.
        Throws:
        java.io.IOException
      • stream

        ArchiveStream stream​(java.io.File archive)
                      throws java.io.IOException
        Reads the given archive file as an ArchiveStream which is used to access individual ArchiveEntry objects within the archive without extracting the archive onto the file system.
        Parameters:
        archive - the archive file to stream
        Returns:
        a new archive stream for the given archive
        Throws:
        java.io.IOException - propagated I/O errors by java.io
      • getFilenameExtension

        java.lang.String getFilenameExtension()
        Returns the filename extension that indicates the file format this archiver handles. E.g .tar" or ".zip". In case of compressed archives, it will return the composite filename extensions, e.g. ".tar.gz"
        Returns:
        a filename extension with a preceding dot