Top Description Inners Constructors Methods
org.apache.commons.compress.archivers.examples

public Class Expander

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .File, .IOException, .InputStream, .OutputStream, java.nio.channels.Channels, .FileChannel, .SeekableByteChannel, java.nio.file.Files, .Path, .StandardOpenOption, java.util.Enumeration, .Iterator, org.apache.commons.compress.archivers.ArchiveEntry, .ArchiveException, .ArchiveInputStream, .ArchiveStreamFactory, org.apache.commons.compress.archivers.sevenz.SevenZFile, org.apache.commons.compress.archivers.tar.TarArchiveEntry, .TarFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry, .ZipFile, org.apache.commons.io.IOUtils, org.apache.commons.io.output.NullOutputStream

Provides a high level API for expanding archives.
Since
1.17

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static interface

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private <T extends ArchiveEntry> void
expand(final Expander.ArchiveEntrySupplier<T> supplier, final Expander.ArchiveEntryBiConsumer<T> writer, final Path
May be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

public void
expand(final ArchiveInputStream<?>
the file to expand
archive
,
final File
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final ArchiveInputStream<?>
the file to expand
archive
,
final Path
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final File
the file to expand
archive
,
final File
the target directory
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final InputStream
the file to expand
archive
,
final File
the target directory
targetDirectory
)

Deprecated this method leaks resources
Expands archive into targetDirectory.
public void
expand(final InputStream
the file to expand
archive
,
final File
the target directory
targetDirectory
,
final CloseableConsumer
is informed about the stream wrapped around the passed in stream
closeableConsumer
)

Expands archive into targetDirectory.

public void
expand(final Path
the file to expand
archive
,
final Path
the target directory
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final SevenZFile
the file to expand
archive
,
final File
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final SevenZFile
the file to expand
archive
,
final Path
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final File
the file to expand
archive
,
final File
the target directory
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final InputStream
the file to expand
archive
,
final File
the target directory
targetDirectory
)

Deprecated this method leaks resources
Expands archive into targetDirectory.
public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final InputStream
the file to expand
archive
,
final File
the target directory
targetDirectory
,
final CloseableConsumer
is informed about the stream wrapped around the passed in stream
closeableConsumer
)

Expands archive into targetDirectory.

public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final InputStream
the file to expand
archive
,
final Path
the target directory
targetDirectory
,
final CloseableConsumer
is informed about the stream wrapped around the passed in stream
closeableConsumer
)

Expands archive into targetDirectory.

public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final Path
the file to expand
archive
,
final Path
the target directory
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final SeekableByteChannel
the file to expand
archive
,
final File
the target directory
targetDirectory
)

Deprecated this method leaks resources
Expands archive into targetDirectory.
public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final SeekableByteChannel
the file to expand
archive
,
final File
the target directory
targetDirectory
,
final CloseableConsumer
is informed about the stream wrapped around the passed in channel
closeableConsumer
)

Expands archive into targetDirectory.

public void
expand(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final SeekableByteChannel
the file to expand
archive
,
final Path
the target directory
targetDirectory
,
final CloseableConsumer
is informed about the stream wrapped around the passed in channel
closeableConsumer
)

Expands archive into targetDirectory.

public void
expand(final TarFile
the file to expand
archive
,
final File
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final TarFile
the file to expand
archive
,
final Path
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final ZipFile
the file to expand
archive
,
final File
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

public void
expand(final ZipFile
the file to expand
archive
,
final Path
the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.
targetDirectory
)

Expands archive into targetDirectory.

private boolean
private Path
toPath(final File targetDirectory)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Expanderback to summary
public Expander()

Method Detail

expandback to summary
private <T extends ArchiveEntry> void expand(final Expander.ArchiveEntrySupplier<T> supplier, final Expander.ArchiveEntryBiConsumer<T> writer, final Path targetDirectory) throws IOException
Parameters
targetDirectory:Path

May be null to simulate output to dev/null on Linux and NUL on Windows.

expandback to summary
public void expand(final ArchiveInputStream<?> archive, final File targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:ArchiveInputStream<?>

the file to expand

targetDirectory:File

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
expandback to summary
public void expand(final ArchiveInputStream<?> archive, final Path targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:ArchiveInputStream<?>

the file to expand

targetDirectory:Path

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
Since
1.22
expandback to summary
public void expand(final File archive, final File targetDirectory) throws IOException, ArchiveException

Expands archive into targetDirectory.

Tries to auto-detect the archive's format.

Parameters
archive:File

the file to expand

targetDirectory:File

the target directory

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
expandback to summary
public void expand(final InputStream archive, final 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:InputStream

the file to expand

targetDirectory:File

the target directory

Annotations
@Deprecated
Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
expandback to summary
public void expand(final InputStream archive, final File targetDirectory, final 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:InputStream

the file to expand

targetDirectory:File

the target directory

closeableConsumer:CloseableConsumer

is informed about the stream wrapped around the passed in stream

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
Since
1.19
expandback to summary
public void expand(final Path archive, final Path targetDirectory) throws IOException, ArchiveException

Expands archive into targetDirectory.

Tries to auto-detect the archive's format.

Parameters
archive:Path

the file to expand

targetDirectory:Path

the target directory

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
Since
1.22
expandback to summary
public void expand(final SevenZFile archive, final File targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:SevenZFile

the file to expand

targetDirectory:File

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
expandback to summary
public void expand(final SevenZFile archive, final Path targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:SevenZFile

the file to expand

targetDirectory:Path

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
Since
1.22
expandback to summary
public void expand(final String format, final File archive, final File targetDirectory) throws IOException, ArchiveException

Expands archive into targetDirectory.

Parameters
format:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:File

the file to expand

targetDirectory:File

the target directory

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
expandback to summary
public void expand(final String format, final InputStream archive, final 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:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:InputStream

the file to expand

targetDirectory:File

the target directory

Annotations
@Deprecated
Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
expandback to summary
public void expand(final String format, final InputStream archive, final File targetDirectory, final 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:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:InputStream

the file to expand

targetDirectory:File

the target directory

closeableConsumer:CloseableConsumer

is informed about the stream wrapped around the passed in stream

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
Since
1.19
expandback to summary
public void expand(final String format, final InputStream archive, final Path targetDirectory, final 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:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:InputStream

the file to expand

targetDirectory:Path

the target directory

closeableConsumer:CloseableConsumer

is informed about the stream wrapped around the passed in stream

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
Since
1.22
expandback to summary
public void expand(final String format, final Path archive, final Path targetDirectory) throws IOException, ArchiveException

Expands archive into targetDirectory.

Parameters
format:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:Path

the file to expand

targetDirectory:Path

the target directory

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
Since
1.22
expandback to summary
public void expand(final String format, final SeekableByteChannel archive, final 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:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:SeekableByteChannel

the file to expand

targetDirectory:File

the target directory

Annotations
@Deprecated
Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
expandback to summary
public void expand(final String format, final SeekableByteChannel archive, final File targetDirectory, final 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:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:SeekableByteChannel

the file to expand

targetDirectory:File

the target directory

closeableConsumer:CloseableConsumer

is informed about the stream wrapped around the passed in channel

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
Since
1.19
expandback to summary
public void expand(final String format, final SeekableByteChannel archive, final Path targetDirectory, final 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:String

the archive format. This uses the same format as accepted by ArchiveStreamFactory.

archive:SeekableByteChannel

the file to expand

targetDirectory:Path

the target directory

closeableConsumer:CloseableConsumer

is informed about the stream wrapped around the passed in channel

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be read for other reasons
Since
1.22
expandback to summary
public void expand(final TarFile archive, final File targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:TarFile

the file to expand

targetDirectory:File

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
Since
1.21
expandback to summary
public void expand(final TarFile archive, final Path targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:TarFile

the file to expand

targetDirectory:Path

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
Since
1.22
expandback to summary
public void expand(final ZipFile archive, final File targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:ZipFile

the file to expand

targetDirectory:File

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
expandback to summary
public void expand(final ZipFile archive, final Path targetDirectory) throws IOException

Expands archive into targetDirectory.

Parameters
archive:ZipFile

the file to expand

targetDirectory:Path

the target directory, may be null to simulate output to dev/null on Linux and NUL on Windows.

Exceptions
IOException:
if an I/O error occurs
Since
1.22
prefersSeekableByteChannelback to summary
private boolean prefersSeekableByteChannel(final String format)
toPathback to summary
private Path toPath(final File targetDirectory)
org.apache.commons.compress.archivers.examples back to summary

private Interface Expander.ArchiveEntryBiConsumer<T extends org.apache.commons.compress.archivers.ArchiveEntry>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void
accept(T entry, OutputStream out)

Method Detail

acceptback to summary
public void accept(T entry, OutputStream out) throws IOException
org.apache.commons.compress.archivers.examples back to summary

private Interface Expander.ArchiveEntrySupplier<T extends org.apache.commons.compress.archivers.ArchiveEntry>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public T
get()

Method Detail

getback to summary
public T get() throws IOException