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

public Class Archiver

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .OutputStream, java.nio.channels.Channels, .FileChannel, .SeekableByteChannel, java.nio.file.FileVisitOption, .FileVisitResult, .Files, .LinkOption, .Path, .SimpleFileVisitor, .StandardOpenOption, java.nio.file.attribute.BasicFileAttributes, java.util.EnumSet, .Objects, org.apache.commons.compress.archivers.ArchiveEntry, .ArchiveException, .ArchiveOutputStream, .ArchiveStreamFactory, org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry, .SevenZOutputFile, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream, org.apache.commons.compress.utils.IOUtils

Provides a high level API for creating archives.
Since
1.17, 1.21 Supports Path.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final EnumSet<FileVisitOption>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
create(final ArchiveOutputStream<?>
the stream to write the new archive to.
target
,
final File
the directory that contains the files to archive.
directory
)

Creates an archive target by recursively including all files and directories in directory.

public void
create(final ArchiveOutputStream<?>
the stream to write the new archive to.
target
,
final Path
the directory that contains the files to archive.
directory
)

Creates an archive target by recursively including all files and directories in directory.

public void
create(final ArchiveOutputStream<?>
the stream to write the new archive to.
target
,
final Path
the directory that contains the files to archive.
directory
,
final EnumSet<FileVisitOption>
linkOptions to configure the traversal of the source directory.
fileVisitOptions
,
final LinkOption...
indicating how symbolic links are handled.
linkOptions
)

Creates an archive target by recursively including all files and directories in directory.

public void
create(final SevenZOutputFile
the file to write the new archive to.
target
,
final File
the directory that contains the files to archive.
directory
)

Creates an archive target by recursively including all files and directories in directory.

public void
create(final SevenZOutputFile
the file to write the new archive to.
target
,
final Path
the directory that contains the files to archive.
directory
)

Creates an archive target by recursively including all files and directories in directory.

public void
create(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final File
the file to write the new archive to.
target
,
final File
the directory that contains the files to archive.
directory
)

Creates an archive target using the format format by recursively including all files and directories in directory.

public void
create(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final OutputStream
the stream to write the new archive to.
target
,
final File
the directory that contains the files to archive.
directory
)

Deprecated this method leaks resources
Creates an archive target using the format format by recursively including all files and directories in directory.
public void
create(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final OutputStream
the stream to write the new archive to.
target
,
final File
the directory that contains the files to archive.
directory
,
final CloseableConsumer
is informed about the stream wrapped around the passed in stream
closeableConsumer
)

Creates an archive target using the format format by recursively including all files and directories in directory.

public void
create(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final Path
the file to write the new archive to.
target
,
final Path
the directory that contains the files to archive.
directory
)

Creates an archive target using the format format by recursively including all files and directories in directory.

public void
create(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final SeekableByteChannel
the channel to write the new archive to.
target
,
final File
the directory that contains the files to archive.
directory
)

Deprecated this method leaks resources
Creates an archive target using the format format by recursively including all files and directories in directory.
public void
create(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final SeekableByteChannel
the channel to write the new archive to.
target
,
final File
the directory that contains the files to archive.
directory
,
final CloseableConsumer
is informed about the stream wrapped around the passed in stream
closeableConsumer
)

Creates an archive target using the format format by recursively including all files and directories in directory.

public void
create(final String
the archive format. This uses the same format as accepted by ArchiveStreamFactory.
format
,
final SeekableByteChannel
the channel to write the new archive to.
target
,
final Path
the directory that contains the files to archive.
directory
)

Creates an archive target using the format format by recursively including all files and directories in directory.

private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_FileVisitOptionback to summary
public static final EnumSet<FileVisitOption> EMPTY_FileVisitOption

No FileVisitOption.

Constructor Detail

Archiverback to summary
public Archiver()

Method Detail

createback to summary
public void create(final ArchiveOutputStream<?> target, final File directory) throws IOException

Creates an archive target by recursively including all files and directories in directory.

Parameters
target:ArchiveOutputStream<?>

the stream to write the new archive to.

directory:File

the directory that contains the files to archive.

Exceptions
IOException:
if an I/O error occurs
createback to summary
public void create(final ArchiveOutputStream<?> target, final Path directory) throws IOException

Creates an archive target by recursively including all files and directories in directory.

Parameters
target:ArchiveOutputStream<?>

the stream to write the new archive to.

directory:Path

the directory that contains the files to archive.

Exceptions
IOException:
if an I/O error occurs or the archive cannot be created for other reasons.
Since
1.21
createback to summary
public void create(final ArchiveOutputStream<?> target, final Path directory, final EnumSet<FileVisitOption> fileVisitOptions, final LinkOption... linkOptions) throws IOException

Creates an archive target by recursively including all files and directories in directory.

Parameters
target:ArchiveOutputStream<?>

the stream to write the new archive to.

directory:Path

the directory that contains the files to archive.

fileVisitOptions:EnumSet<FileVisitOption>

linkOptions to configure the traversal of the source directory.

linkOptions:LinkOption[]

indicating how symbolic links are handled.

Exceptions
IOException:
if an I/O error occurs or the archive cannot be created for other reasons.
Since
1.21
createback to summary
public void create(final SevenZOutputFile target, final File directory) throws IOException

Creates an archive target by recursively including all files and directories in directory.

Parameters
target:SevenZOutputFile

the file to write the new archive to.

directory:File

the directory that contains the files to archive.

Exceptions
IOException:
if an I/O error occurs
createback to summary
public void create(final SevenZOutputFile target, final Path directory) throws IOException

Creates an archive target by recursively including all files and directories in directory.

Parameters
target:SevenZOutputFile

the file to write the new archive to.

directory:Path

the directory that contains the files to archive.

Exceptions
IOException:
if an I/O error occurs
Since
1.21
createback to summary
public void create(final String format, final File target, final File directory) throws IOException, ArchiveException

Creates an archive target using the format format by recursively including all files and directories in directory.

Parameters
format:String

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

target:File

the file to write the new archive to.

directory:File

the directory that contains the files to archive.

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be created for other reasons
createback to summary
public void create(final String format, final OutputStream target, final File directory) throws IOException, ArchiveException

Deprecated

this method leaks resources

Creates an archive target using the format format by recursively including all files and directories in directory.

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:String

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

target:OutputStream

the stream to write the new archive to.

directory:File

the directory that contains the files to archive.

Annotations
@Deprecated
Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be created for other reasons
createback to summary
public void create(final String format, final OutputStream target, final File directory, final CloseableConsumer closeableConsumer) throws IOException, ArchiveException

Creates an archive target using the format format by recursively including all files and directories in directory.

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.

target:OutputStream

the stream to write the new archive to.

directory:File

the directory that contains the files to archive.

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 created for other reasons
Since
1.19
createback to summary
public void create(final String format, final Path target, final Path directory) throws IOException, ArchiveException

Creates an archive target using the format format by recursively including all files and directories in directory.

Parameters
format:String

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

target:Path

the file to write the new archive to.

directory:Path

the directory that contains the files to archive.

Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be created for other reasons
Since
1.21
createback to summary
public void create(final String format, final SeekableByteChannel target, final File directory) throws IOException, ArchiveException

Deprecated

this method leaks resources

Creates an archive target using the format format by recursively including all files and directories in directory.

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:String

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

target:SeekableByteChannel

the channel to write the new archive to.

directory:File

the directory that contains the files to archive.

Annotations
@Deprecated
Exceptions
IOException:
if an I/O error occurs
ArchiveException:
if the archive cannot be created for other reasons
createback to summary
public void create(final String format, final SeekableByteChannel target, final File directory, final CloseableConsumer closeableConsumer) throws IOException, ArchiveException

Creates an archive target using the format format by recursively including all files and directories in directory.

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.

target:SeekableByteChannel

the channel to write the new archive to.

directory:File

the directory that contains the files to archive.

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 created for other reasons
Since
1.19
createback to summary
public void create(final String format, final SeekableByteChannel target, final Path directory) throws IOException

Creates an archive target using the format format by recursively including all files and directories in directory.

Parameters
format:String

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

target:SeekableByteChannel

the channel to write the new archive to.

directory:Path

the directory that contains the files to archive.

Exceptions
IOException:
if an I/O error occurs
IllegalStateException:
if the format does not support SeekableByteChannel.
prefersSeekableByteChannelback to summary
private boolean prefersSeekableByteChannel(final String format)
org.apache.commons.compress.archivers.examples back to summary

private Class Archiver.ArchiverFileVisitor<O extends org.apache.commons.compress.archivers.ArchiveOutputStream<E>, E extends org.apache.commons.compress.archivers.ArchiveEntry>

extends SimpleFileVisitor<Path>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Path
private final LinkOption[]
private final O

Constructor Summary

AccessConstructor and Description
private
ArchiverFileVisitor(final O target, final Path directory, final LinkOption... linkOptions)

Method Summary

Modifier and TypeMethod and Description
public FileVisitResult
preVisitDirectory(final Path
a reference to the directory
dir
,
final BasicFileAttributes
the directory's basic attributes
attrs
)

Overrides java.nio.file.SimpleFileVisitor.preVisitDirectory.

Implements java.nio.file.FileVisitor.preVisitDirectory.

Invoked for a directory before entries in the directory are visited.
protected FileVisitResult
visit(final Path path, final BasicFileAttributes attrs, final boolean isFile)

public FileVisitResult
visitFile(final Path
a reference to the file
file
,
final BasicFileAttributes
the file's basic attributes
attrs
)

Overrides java.nio.file.SimpleFileVisitor.visitFile.

Implements java.nio.file.FileVisitor.visitFile.

Invoked for a file in a directory.
Inherited from java.nio.file.SimpleFileVisitor:
postVisitDirectoryvisitFileFailed

Field Detail

directoryback to summary
private final Path directory
linkOptionsback to summary
private final LinkOption[] linkOptions
targetback to summary
private final O target

Constructor Detail

ArchiverFileVisitorback to summary
private ArchiverFileVisitor(final O target, final Path directory, final LinkOption... linkOptions)

Method Detail

preVisitDirectoryback to summary
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException

Overrides java.nio.file.SimpleFileVisitor.preVisitDirectory.

Implements java.nio.file.FileVisitor.preVisitDirectory.

Doc from java.nio.file.SimpleFileVisitor.preVisitDirectory.

Invoked for a directory before entries in the directory are visited.

Unless overridden, this method returns CONTINUE.

Parameters
dir:Path

Doc from java.nio.file.FileVisitor.preVisitDirectory.

a reference to the directory

attrs:BasicFileAttributes

Doc from java.nio.file.FileVisitor.preVisitDirectory.

the directory's basic attributes

Returns:FileVisitResult

Doc from java.nio.file.FileVisitor.preVisitDirectory.

the visit result

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.file.FileVisitor.preVisitDirectory.

if an I/O error occurs

visitback to summary
protected FileVisitResult visit(final Path path, final BasicFileAttributes attrs, final boolean isFile) throws IOException
visitFileback to summary
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException

Overrides java.nio.file.SimpleFileVisitor.visitFile.

Implements java.nio.file.FileVisitor.visitFile.

Doc from java.nio.file.SimpleFileVisitor.visitFile.

Invoked for a file in a directory.

Unless overridden, this method returns CONTINUE.

Parameters
file:Path

Doc from java.nio.file.FileVisitor.visitFile.

a reference to the file

attrs:BasicFileAttributes

Doc from java.nio.file.FileVisitor.visitFile.

the file's basic attributes

Returns:FileVisitResult

Doc from java.nio.file.FileVisitor.visitFile.

the visit result

Annotations
@Override
Exceptions
IOException:

Doc from java.nio.file.FileVisitor.visitFile.

if an I/O error occurs