Package org.apache.commons.compress.archivers.examples

# Class Expander

java.lang.Object
org.apache.commons.compress.archivers.examples.Expander

public class Expander extends Object
Provides a high level API for expanding archives.

Since:
  1.17

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Expander()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `expand(File archive, File targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(InputStream archive, File targetDirectory)`
  Deprecated.
  this method leaks resources
  `void`
  `expand(InputStream archive, File targetDirectory, CloseableConsumer closeableConsumer)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(String format, File archive, File targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(String format, InputStream archive, File targetDirectory)`
  Deprecated.
  this method leaks resources
  `void`
  `expand(String format, InputStream archive, File targetDirectory, CloseableConsumer closeableConsumer)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(String format, InputStream archive, Path targetDirectory, CloseableConsumer closeableConsumer)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(String format, SeekableByteChannel archive, File targetDirectory)`
  Deprecated.
  this method leaks resources
  `void`
  `expand(String format, SeekableByteChannel archive, File targetDirectory, CloseableConsumer closeableConsumer)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(String format, SeekableByteChannel archive, Path targetDirectory, CloseableConsumer closeableConsumer)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(String format, Path archive, Path targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(Path archive, Path targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(ArchiveInputStream<?> archive, File targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(ArchiveInputStream<?> archive, Path targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(SevenZFile archive, File targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(SevenZFile archive, Path targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(TarFile archive, File targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(TarFile archive, Path targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(ZipFile archive, File targetDirectory)`
  Expands `archive` into `targetDirectory`.
  `void`
  `expand(ZipFile archive, Path targetDirectory)`
  Expands `archive` into `targetDirectory`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Expander

    public Expander()

- ## Method Details

  - ### expand

    public void expand(ArchiveInputStream<?> archive, File targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs

  - ### expand

    public void expand(ArchiveInputStream<?> archive, Path targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs
    Since:
      1.22

  - ### expand

    public void expand(File archive, File targetDirectory) throws IOException, ArchiveException
    Expands `archive` into `targetDirectory`.

    Tries to auto-detect the archive's format.

    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons

  - ### expand

    @Deprecated public void expand(InputStream archive, File targetDirectory) throws 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 target directory
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons

  - ### expand

    public void expand(InputStream archive, File targetDirectory, CloseableConsumer closeableConsumer) throws 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 target directory
      `closeableConsumer` - is informed about the stream wrapped around the passed in stream
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons
    Since:
      1.19

  - ### expand

    public void expand(Path archive, Path targetDirectory) throws IOException, ArchiveException
    Expands `archive` into `targetDirectory`.

    Tries to auto-detect the archive's format.

    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons
    Since:
      1.22

  - ### expand

    public void expand(SevenZFile archive, File targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs

  - ### expand

    public void expand(SevenZFile archive, Path targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs
    Since:
      1.22

  - ### expand

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

  - ### expand

    @Deprecated public void expand(String format, InputStream archive, File targetDirectory) throws 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:
      `format` - the archive format. This uses the same format as accepted by `ArchiveStreamFactory`.
      `archive` - the file to expand
      `targetDirectory` - the target directory
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons

  - ### expand

    public void expand(String format, InputStream archive, File targetDirectory, CloseableConsumer closeableConsumer) throws 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:
      `format` - the archive format. This uses the same format as accepted by `ArchiveStreamFactory`.
      `archive` - the file to expand
      `targetDirectory` - the target directory
      `closeableConsumer` - is informed about the stream wrapped around the passed in stream
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons
    Since:
      1.19

  - ### expand

    public void expand(String format, InputStream archive, Path targetDirectory, CloseableConsumer closeableConsumer) throws 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:
      `format` - the archive format. This uses the same format as accepted by `ArchiveStreamFactory`.
      `archive` - the file to expand
      `targetDirectory` - the target directory
      `closeableConsumer` - is informed about the stream wrapped around the passed in stream
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons
    Since:
      1.22

  - ### expand

    public void expand(String format, Path archive, Path targetDirectory) throws IOException, ArchiveException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `format` - the archive format. This uses the same format as accepted by `ArchiveStreamFactory`.
      `archive` - the file to expand
      `targetDirectory` - the target directory
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons
    Since:
      1.22

  - ### expand

    @Deprecated public void expand(String format, SeekableByteChannel archive, File targetDirectory) throws 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:
      `format` - the archive format. This uses the same format as accepted by `ArchiveStreamFactory`.
      `archive` - the file to expand
      `targetDirectory` - the target directory
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons

  - ### expand

    public void expand(String format, SeekableByteChannel archive, File targetDirectory, CloseableConsumer closeableConsumer) throws 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:
      `format` - the archive format. This uses the same format as accepted by `ArchiveStreamFactory`.
      `archive` - the file to expand
      `targetDirectory` - the target directory
      `closeableConsumer` - is informed about the stream wrapped around the passed in channel
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons
    Since:
      1.19

  - ### expand

    public void expand(String format, SeekableByteChannel archive, Path targetDirectory, CloseableConsumer closeableConsumer) throws 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:
      `format` - the archive format. This uses the same format as accepted by `ArchiveStreamFactory`.
      `archive` - the file to expand
      `targetDirectory` - the target directory
      `closeableConsumer` - is informed about the stream wrapped around the passed in channel
    Throws:
      `IOException` - if an I/O error occurs
      `ArchiveException` - if the archive cannot be read for other reasons
    Since:
      1.22

  - ### expand

    public void expand(TarFile archive, File targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs
    Since:
      1.21

  - ### expand

    public void expand(TarFile archive, Path targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs
    Since:
      1.22

  - ### expand

    public void expand(ZipFile archive, File targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs

  - ### expand

    public void expand(ZipFile archive, Path targetDirectory) throws IOException
    Expands `archive` into `targetDirectory`.
    Parameters:
      `archive` - the file to expand
      `targetDirectory` - the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
    Throws:
      `IOException` - if an I/O error occurs
    Since:
      1.22