Class Archiver
- java.lang.Object
-
- org.apache.commons.compress.archivers.examples.Archiver
-
public class Archiver extends java.lang.ObjectProvides a high level API for creating archives.- Since:
- 1.17
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceArchiver.ArchiveEntryConsumerprivate static interfaceArchiver.ArchiveEntryCreatorprivate static interfaceArchiver.Finisher
-
Constructor Summary
Constructors Constructor Description Archiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidcreate(java.io.File directory, Archiver.ArchiveEntryCreator creator, Archiver.ArchiveEntryConsumer consumer, Archiver.Finisher finisher)voidcreate(java.lang.String format, java.io.File target, java.io.File directory)Creates an archivetargetusing the formatformatby recursively including all files and directories indirectory.private voidcreate(java.lang.String prefix, java.io.File directory, Archiver.ArchiveEntryCreator creator, Archiver.ArchiveEntryConsumer consumer)voidcreate(java.lang.String format, java.io.OutputStream target, java.io.File directory)Deprecated.this method leaks resourcesvoidcreate(java.lang.String format, java.io.OutputStream target, java.io.File directory, CloseableConsumer closeableConsumer)Creates an archivetargetusing the formatformatby recursively including all files and directories indirectory.voidcreate(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.io.File directory)Deprecated.this method leaks resourcesvoidcreate(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.io.File directory, CloseableConsumer closeableConsumer)Creates an archivetargetusing the formatformatby recursively including all files and directories indirectory.voidcreate(ArchiveOutputStream target, java.io.File directory)Creates an archivetargetby recursively including all files and directories indirectory.voidcreate(SevenZOutputFile target, java.io.File directory)Creates an archivetargetby recursively including all files and directories indirectory.private booleanprefersSeekableByteChannel(java.lang.String format)
-
-
-
Method Detail
-
create
public void create(java.lang.String format, java.io.File target, java.io.File directory) throws java.io.IOException, ArchiveExceptionCreates an archivetargetusing the formatformatby recursively including all files and directories indirectory.- Parameters:
format- the archive format. This uses the same format as accepted byArchiveStreamFactory.target- the file to write the new archive to.directory- the directory that contains the files to archive.- Throws:
java.io.IOException- if an I/O error occursArchiveException- if the archive cannot be created for other reasons
-
create
@Deprecated public void create(java.lang.String format, java.io.OutputStream target, java.io.File directory) throws java.io.IOException, ArchiveExceptionDeprecated.this method leaks resourcesCreates an archivetargetusing the formatformatby recursively including all files and directories indirectory.This method creates a wrapper around the target stream which is never closed and thus leaks resources, please use
create(String,OutputStream,File,CloseableConsumer)instead.- Parameters:
format- the archive format. This uses the same format as accepted byArchiveStreamFactory.target- the stream to write the new archive to.directory- the directory that contains the files to archive.- Throws:
java.io.IOException- if an I/O error occursArchiveException- if the archive cannot be created for other reasons
-
create
public void create(java.lang.String format, java.io.OutputStream target, java.io.File directory, CloseableConsumer closeableConsumer) throws java.io.IOException, ArchiveExceptionCreates an archivetargetusing the formatformatby recursively including all files and directories indirectory.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
closeableConsumercallback as soon as it is no longer needed by this class.- Parameters:
format- the archive format. This uses the same format as accepted byArchiveStreamFactory.target- the stream to write the new archive to.directory- the directory that contains the files to archive.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 created for other reasons- Since:
- 1.19
-
create
@Deprecated public void create(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.io.File directory) throws java.io.IOException, ArchiveExceptionDeprecated.this method leaks resourcesCreates an archivetargetusing the formatformatby recursively including all files and directories indirectory.This method creates a wrapper around the target channel which is never closed and thus leaks resources, please use
create(String,SeekableByteChannel,File,CloseableConsumer)instead.- Parameters:
format- the archive format. This uses the same format as accepted byArchiveStreamFactory.target- the channel to write the new archive to.directory- the directory that contains the files to archive.- Throws:
java.io.IOException- if an I/O error occursArchiveException- if the archive cannot be created for other reasons
-
create
public void create(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.io.File directory, CloseableConsumer closeableConsumer) throws java.io.IOException, ArchiveExceptionCreates an archivetargetusing the formatformatby recursively including all files and directories indirectory.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
closeableConsumercallback as soon as it is no longer needed by this class.- Parameters:
format- the archive format. This uses the same format as accepted byArchiveStreamFactory.target- the channel to write the new archive to.directory- the directory that contains the files to archive.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 created for other reasons- Since:
- 1.19
-
create
public void create(ArchiveOutputStream target, java.io.File directory) throws java.io.IOException, ArchiveException
Creates an archivetargetby recursively including all files and directories indirectory.- Parameters:
target- the stream to write the new archive to.directory- the directory that contains the files to archive.- Throws:
java.io.IOException- if an I/O error occursArchiveException- if the archive cannot be created for other reasons
-
create
public void create(SevenZOutputFile target, java.io.File directory) throws java.io.IOException
Creates an archivetargetby recursively including all files and directories indirectory.- Parameters:
target- the file to write the new archive to.directory- the directory that contains the files to archive.- Throws:
java.io.IOException- if an I/O error occurs
-
prefersSeekableByteChannel
private boolean prefersSeekableByteChannel(java.lang.String format)
-
create
private void create(java.io.File directory, Archiver.ArchiveEntryCreator creator, Archiver.ArchiveEntryConsumer consumer, Archiver.Finisher finisher) throws java.io.IOException- Throws:
java.io.IOException
-
create
private void create(java.lang.String prefix, java.io.File directory, Archiver.ArchiveEntryCreator creator, Archiver.ArchiveEntryConsumer consumer) throws java.io.IOException- Throws:
java.io.IOException
-
-