Class Expander
- java.lang.Object
-
- org.apache.commons.compress.archivers.examples.Expander
-
public class Expander extends java.lang.Object
Provides a high level API for expanding archives.- Since:
- 1.17
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
Expander.ArchiveEntrySupplier
private static interface
Expander.EntryWriter
-
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)
Expandsarchive
intotargetDirectory
.void
expand(java.io.InputStream archive, java.io.File targetDirectory)
Deprecated.this method leaks resourcesvoid
expand(java.io.InputStream archive, java.io.File targetDirectory, CloseableConsumer closeableConsumer)
Expandsarchive
intotargetDirectory
.void
expand(java.lang.String format, java.io.File archive, java.io.File targetDirectory)
Expandsarchive
intotargetDirectory
.void
expand(java.lang.String format, java.io.InputStream archive, java.io.File targetDirectory)
Deprecated.this method leaks resourcesvoid
expand(java.lang.String format, java.io.InputStream archive, java.io.File targetDirectory, CloseableConsumer closeableConsumer)
Expandsarchive
intotargetDirectory
.void
expand(java.lang.String format, java.nio.channels.SeekableByteChannel archive, java.io.File targetDirectory)
Deprecated.this method leaks resourcesvoid
expand(java.lang.String format, java.nio.channels.SeekableByteChannel archive, java.io.File targetDirectory, CloseableConsumer closeableConsumer)
Expandsarchive
intotargetDirectory
.void
expand(ArchiveInputStream archive, java.io.File targetDirectory)
Expandsarchive
intotargetDirectory
.private void
expand(Expander.ArchiveEntrySupplier supplier, Expander.EntryWriter writer, java.io.File targetDirectory)
void
expand(SevenZFile archive, java.io.File targetDirectory)
Expandsarchive
intotargetDirectory
.void
expand(ZipFile archive, java.io.File targetDirectory)
Expandsarchive
intotargetDirectory
.private boolean
prefersSeekableByteChannel(java.lang.String format)
-
-
-
Method Detail
-
expand
public void expand(java.io.File archive, java.io.File targetDirectory) throws java.io.IOException, ArchiveException
Expandsarchive
intotargetDirectory
.Tries to auto-detect the archive's format.
- Parameters:
archive
- the file to expandtargetDirectory
- the directory to write to- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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
Expandsarchive
intotargetDirectory
.- Parameters:
archive
- the file to expandtargetDirectory
- the directory to write toformat
- the archive format. This uses the same format as accepted byArchiveStreamFactory
.- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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 resourcesExpandsarchive
intotargetDirectory
.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 expandtargetDirectory
- the directory to write to- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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
Expandsarchive
intotargetDirectory
.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 expandtargetDirectory
- the directory to write tocloseableConsumer
- is informed about the stream wrapped around the passed in stream- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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 resourcesExpandsarchive
intotargetDirectory
.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 expandtargetDirectory
- the directory to write toformat
- the archive format. This uses the same format as accepted byArchiveStreamFactory
.- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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
Expandsarchive
intotargetDirectory
.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 expandtargetDirectory
- the directory to write toformat
- the archive format. This uses the same format as accepted byArchiveStreamFactory
.closeableConsumer
- is informed about the stream wrapped around the passed in stream- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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 resourcesExpandsarchive
intotargetDirectory
.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 expandtargetDirectory
- the directory to write toformat
- the archive format. This uses the same format as accepted byArchiveStreamFactory
.- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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
Expandsarchive
intotargetDirectory
.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 expandtargetDirectory
- the directory to write toformat
- the archive format. This uses the same format as accepted byArchiveStreamFactory
.closeableConsumer
- is informed about the stream wrapped around the passed in channel- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- 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
Expandsarchive
intotargetDirectory
.- Parameters:
archive
- the file to expandtargetDirectory
- the directory to write to- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- if the archive cannot be read for other reasons
-
expand
public void expand(ZipFile archive, java.io.File targetDirectory) throws java.io.IOException, ArchiveException
Expandsarchive
intotargetDirectory
.- Parameters:
archive
- the file to expandtargetDirectory
- the directory to write to- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- if the archive cannot be read for other reasons
-
expand
public void expand(SevenZFile archive, java.io.File targetDirectory) throws java.io.IOException, ArchiveException
Expandsarchive
intotargetDirectory
.- Parameters:
archive
- the file to expandtargetDirectory
- the directory to write to- Throws:
java.io.IOException
- if an I/O error occursArchiveException
- if the archive cannot be read for other reasons
-
prefersSeekableByteChannel
private boolean prefersSeekableByteChannel(java.lang.String format)
-
expand
private void expand(Expander.ArchiveEntrySupplier supplier, Expander.EntryWriter writer, java.io.File targetDirectory) throws java.io.IOException
- Throws:
java.io.IOException
-
-