Class Expander


  • public class Expander
    extends java.lang.Object
    Provides a high level API for expanding archives.
    Since:
    1.17
    • Constructor Summary

      Constructors 
      Constructor Description
      Expander()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void expand​(java.io.File archive, java.io.File targetDirectory)
      Expands archive into targetDirectory.
      void expand​(java.io.InputStream archive, java.io.File targetDirectory)
      Deprecated.
      this method leaks resources
      void expand​(java.io.InputStream archive, java.io.File targetDirectory, CloseableConsumer closeableConsumer)
      Expands archive into targetDirectory.
      void expand​(java.lang.String format, java.io.File archive, java.io.File targetDirectory)
      Expands archive into targetDirectory.
      void expand​(java.lang.String format, java.io.InputStream archive, java.io.File targetDirectory)
      Deprecated.
      this method leaks resources
      void expand​(java.lang.String format, java.io.InputStream archive, java.io.File targetDirectory, CloseableConsumer closeableConsumer)
      Expands archive into targetDirectory.
      void expand​(java.lang.String format, java.nio.channels.SeekableByteChannel archive, java.io.File targetDirectory)
      Deprecated.
      this method leaks resources
      void expand​(java.lang.String format, java.nio.channels.SeekableByteChannel archive, java.io.File targetDirectory, CloseableConsumer closeableConsumer)
      Expands archive into targetDirectory.
      void expand​(ArchiveInputStream archive, java.io.File targetDirectory)
      Expands archive into targetDirectory.
      private void expand​(Expander.ArchiveEntrySupplier supplier, Expander.EntryWriter writer, java.io.File targetDirectory)  
      void expand​(SevenZFile archive, java.io.File targetDirectory)
      Expands archive into targetDirectory.
      void expand​(ZipFile archive, java.io.File targetDirectory)
      Expands archive into targetDirectory.
      private boolean prefersSeekableByteChannel​(java.lang.String format)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Expander

        public Expander()
    • Method Detail

      • expand

        public void expand​(java.io.File archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.

        Tries to auto-detect the archive's format.

        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • expand

        public void expand​(java.lang.String format,
                           java.io.File archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.
        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        format - the archive format. This uses the same format as accepted by ArchiveStreamFactory.
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • expand

        @Deprecated
        public void expand​(java.io.InputStream archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Deprecated.
        this method leaks resources
        Expands archive into targetDirectory.

        Tries to auto-detect the archive's format.

        This method creates a wrapper around the archive stream which is never closed and thus leaks resources, please use expand(InputStream,File,CloseableConsumer) instead.

        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • expand

        public void expand​(java.io.InputStream archive,
                           java.io.File targetDirectory,
                           CloseableConsumer closeableConsumer)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.

        Tries to auto-detect the archive's format.

        This method creates a wrapper around the archive stream and the caller of this method is responsible for closing it - probably at the same time as closing the stream itself. The caller is informed about the wrapper object via the closeableConsumer callback as soon as it is no longer needed by this class.

        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        closeableConsumer - is informed about the stream wrapped around the passed in stream
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
        Since:
        1.19
      • expand

        @Deprecated
        public void expand​(java.lang.String format,
                           java.io.InputStream archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Deprecated.
        this method leaks resources
        Expands archive into targetDirectory.

        This method creates a wrapper around the archive stream which is never closed and thus leaks resources, please use expand(String,InputStream,File,CloseableConsumer) instead.

        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        format - the archive format. This uses the same format as accepted by ArchiveStreamFactory.
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • expand

        public void expand​(java.lang.String format,
                           java.io.InputStream archive,
                           java.io.File targetDirectory,
                           CloseableConsumer closeableConsumer)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.

        This method creates a wrapper around the archive stream and the caller of this method is responsible for closing it - probably at the same time as closing the stream itself. The caller is informed about the wrapper object via the closeableConsumer callback as soon as it is no longer needed by this class.

        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        format - the archive format. This uses the same format as accepted by ArchiveStreamFactory.
        closeableConsumer - is informed about the stream wrapped around the passed in stream
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
        Since:
        1.19
      • expand

        @Deprecated
        public void expand​(java.lang.String format,
                           java.nio.channels.SeekableByteChannel archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Deprecated.
        this method leaks resources
        Expands archive into targetDirectory.

        This method creates a wrapper around the archive channel which is never closed and thus leaks resources, please use expand(String,SeekableByteChannel,File,CloseableConsumer) instead.

        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        format - the archive format. This uses the same format as accepted by ArchiveStreamFactory.
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • expand

        public void expand​(java.lang.String format,
                           java.nio.channels.SeekableByteChannel archive,
                           java.io.File targetDirectory,
                           CloseableConsumer closeableConsumer)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.

        This method creates a wrapper around the archive channel and the caller of this method is responsible for closing it - probably at the same time as closing the channel itself. The caller is informed about the wrapper object via the closeableConsumer callback as soon as it is no longer needed by this class.

        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        format - the archive format. This uses the same format as accepted by ArchiveStreamFactory.
        closeableConsumer - is informed about the stream wrapped around the passed in channel
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
        Since:
        1.19
      • expand

        public void expand​(ArchiveInputStream archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.
        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • expand

        public void expand​(ZipFile archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.
        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • expand

        public void expand​(SevenZFile archive,
                           java.io.File targetDirectory)
                    throws java.io.IOException,
                           ArchiveException
        Expands archive into targetDirectory.
        Parameters:
        archive - the file to expand
        targetDirectory - the directory to write to
        Throws:
        java.io.IOException - if an I/O error occurs
        ArchiveException - if the archive cannot be read for other reasons
      • prefersSeekableByteChannel

        private boolean prefersSeekableByteChannel​(java.lang.String format)