Class Archiver
- java.lang.Object
-
- org.apache.commons.compress.archivers.examples.Archiver
-
public class Archiver extends java.lang.Object
Provides a high level API for creating archives.- Since:
- 1.17, 1.21 Supports
Path
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Archiver.ArchiverFileVisitor<O extends ArchiveOutputStream<E>,E extends ArchiveEntry>
-
Field Summary
Fields Modifier and Type Field Description static java.util.EnumSet<java.nio.file.FileVisitOption>
EMPTY_FileVisitOption
NoFileVisitOption
.
-
Constructor Summary
Constructors Constructor Description Archiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
create(java.lang.String format, java.io.File target, java.io.File directory)
Creates an archivetarget
using the formatformat
by recursively including all files and directories indirectory
.void
create(java.lang.String format, java.io.OutputStream target, java.io.File directory)
Deprecated.this method leaks resourcesvoid
create(java.lang.String format, java.io.OutputStream target, java.io.File directory, CloseableConsumer closeableConsumer)
Creates an archivetarget
using the formatformat
by recursively including all files and directories indirectory
.void
create(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.io.File directory)
Deprecated.this method leaks resourcesvoid
create(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.io.File directory, CloseableConsumer closeableConsumer)
Creates an archivetarget
using the formatformat
by recursively including all files and directories indirectory
.void
create(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.nio.file.Path directory)
Creates an archivetarget
using the formatformat
by recursively including all files and directories indirectory
.void
create(java.lang.String format, java.nio.file.Path target, java.nio.file.Path directory)
Creates an archivetarget
using the formatformat
by recursively including all files and directories indirectory
.void
create(ArchiveOutputStream<?> target, java.io.File directory)
Creates an archivetarget
by recursively including all files and directories indirectory
.void
create(ArchiveOutputStream<?> target, java.nio.file.Path directory)
Creates an archivetarget
by recursively including all files and directories indirectory
.void
create(ArchiveOutputStream<?> target, java.nio.file.Path directory, java.util.EnumSet<java.nio.file.FileVisitOption> fileVisitOptions, java.nio.file.LinkOption... linkOptions)
Creates an archivetarget
by recursively including all files and directories indirectory
.void
create(SevenZOutputFile target, java.io.File directory)
Creates an archivetarget
by recursively including all files and directories indirectory
.void
create(SevenZOutputFile target, java.nio.file.Path directory)
Creates an archivetarget
by recursively including all files and directories indirectory
.private boolean
prefersSeekableByteChannel(java.lang.String format)
-
-
-
Method Detail
-
create
public void create(ArchiveOutputStream<?> target, java.io.File directory) throws java.io.IOException
Creates an archivetarget
by 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 occurs
-
create
public void create(ArchiveOutputStream<?> target, java.nio.file.Path directory) throws java.io.IOException
Creates an archivetarget
by 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 occurs or the archive cannot be created for other reasons.- Since:
- 1.21
-
create
public void create(ArchiveOutputStream<?> target, java.nio.file.Path directory, java.util.EnumSet<java.nio.file.FileVisitOption> fileVisitOptions, java.nio.file.LinkOption... linkOptions) throws java.io.IOException
Creates an archivetarget
by 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.fileVisitOptions
- linkOptions to configure the traversal of the sourcedirectory
.linkOptions
- indicating how symbolic links are handled.- Throws:
java.io.IOException
- if an I/O error occurs or the archive cannot be created for other reasons.- Since:
- 1.21
-
create
public void create(SevenZOutputFile target, java.io.File directory) throws java.io.IOException
Creates an archivetarget
by 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
-
create
public void create(SevenZOutputFile target, java.nio.file.Path directory) throws java.io.IOException
Creates an archivetarget
by 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- Since:
- 1.21
-
create
public void create(java.lang.String format, java.io.File target, java.io.File directory) throws java.io.IOException, ArchiveException
Creates an archivetarget
using the formatformat
by 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, ArchiveException
Deprecated.this method leaks resourcesCreates an archivetarget
using the formatformat
by 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, ArchiveException
Creates an archivetarget
using the formatformat
by 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
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 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
public void create(java.lang.String format, java.nio.file.Path target, java.nio.file.Path directory) throws java.io.IOException, ArchiveException
Creates an archivetarget
using the formatformat
by 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- Since:
- 1.21
-
create
@Deprecated public void create(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.io.File directory) throws java.io.IOException, ArchiveException
Deprecated.this method leaks resourcesCreates an archivetarget
using the formatformat
by 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, ArchiveException
Creates an archivetarget
using the formatformat
by 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
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 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(java.lang.String format, java.nio.channels.SeekableByteChannel target, java.nio.file.Path directory) throws java.io.IOException
Creates an archivetarget
using the formatformat
by recursively including all files and directories indirectory
.- 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 occursjava.lang.IllegalStateException
- if the format does not supportSeekableByteChannel
.
-
prefersSeekableByteChannel
private boolean prefersSeekableByteChannel(java.lang.String format)
-
-