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

public Class SevenZOutputFile

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Static Imports
java.nio.charset.StandardCharsets.UTF_16LE

Writes a 7z file.
Since
1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private CountingOutputStream[]
private final Map<SevenZArchiveEntry, long[]>
private AES256Options
private final SeekableByteChannel
private final CRC32
private Iterable<? extends SevenZMethodConfiguration>
private final CRC32
private CountingOutputStream
private long
private final List<SevenZArchiveEntry>
private boolean
private int

Constructor Summary

AccessConstructor and Description
public
SevenZOutputFile(final File
the file to write to
fileName
)

Opens file to write a 7z archive to.

public
SevenZOutputFile(final File
the file to write to
fileName
,
final char[]
optional password if the archive has to be encrypted
password
)

Opens file to write a 7z archive to.

public
SevenZOutputFile(final SeekableByteChannel
the channel to write to
channel
)

Prepares channel to write a 7z archive to.

public
SevenZOutputFile(final SeekableByteChannel
the channel to write to
channel
,
final char[]
optional password if the archive has to be encrypted
password
)

Prepares channel to write a 7z archive to.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes the archive, calling finish if necessary.
public void
closeArchiveEntry()

Closes the archive entry.

public SevenZArchiveEntry

Returns:

the ArchiveEntry set up with details from the file
createArchiveEntry
(final File
file to create an entry from
inputFile
,
final String
the name to use
entryName
)

Creates an archive entry using the inputFile and entryName provided.

public SevenZArchiveEntry

Returns:

the ArchiveEntry set up with details from the file
createArchiveEntry
(final Path
path to create an entry from
inputPath
,
final String
the name to use
entryName
,
final LinkOption...
options indicating how symbolic links are handled.
options
)

Creates an archive entry using the inputPath and entryName provided.

private void
fillDates(final Path inputPath, final SevenZArchiveEntry entry, final LinkOption... options)

public void
finish()

Finishes the addition of entries to this archive, without closing it.

private Iterable<? extends SevenZMethodConfiguration>
private OutputStream
public void
putArchiveEntry(final ArchiveEntry
describes the entry
archiveEntry
)

Records an archive entry to add.
public void
putArchiveEntry(final SevenZArchiveEntry
describes the entry
archiveEntry
)

Records an archive entry to add.

private static <T> Iterable<T>
reverse(final Iterable<T> i)

public void
setContentCompression(final SevenZMethod
the default compression method
method
)

Sets the default compression method to use for entry contents - the default is LZMA2.

public void
setContentMethods(final Iterable<? extends SevenZMethodConfiguration>
the default (compression) methods
methods
)

Sets the default (compression) methods to use for entry contents - the default is LZMA2.

private CountingOutputStream
public void
write(final byte[]
The byte array to be written.
b
)

Writes a byte array to the current archive entry.

public void
write(final byte[]
The byte array to be written.
b
,
final int
offset into the array to start writing from
off
,
final int
number of bytes to write
len
)

Writes part of a byte array to the current archive entry.

public void
write(final InputStream
the data source.
inputStream
)

Writes all of the given input stream to the current archive entry.

public void
write(final int
The byte to be written.
b
)

Writes a byte to the current archive entry.

public void
write(final Path
the data source.
path
,
final OpenOption...
options specifying how the file is opened.
options
)

Writes all of the given input stream to the current archive entry.

private void
writeBits(final DataOutput header, final BitSet bits, final int length)

private void
private void
private void
private void
private void
private void
private void
writeFileNames(final DataOutput header)

private void
writeFilesInfo(final DataOutput header)

private void
private void
writeFolder(final DataOutput header, final SevenZArchiveEntry entry)

private void
writeHeader(final DataOutput header)

private void
writePackInfo(final DataOutput header)

private void
private void
private void
private void
writeUint64(final DataOutput header, long value)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

additionalCountingStreamsback to summary
private CountingOutputStream[] additionalCountingStreams
additionalSizesback to summary
private final Map<SevenZArchiveEntry, long[]> additionalSizes
aes256Optionsback to summary
private AES256Options aes256Options
channelback to summary
private final SeekableByteChannel channel
compressedCrc32back to summary
private final CRC32 compressedCrc32
contentMethodsback to summary
private Iterable<? extends SevenZMethodConfiguration> contentMethods
crc32back to summary
private final CRC32 crc32
currentOutputStreamback to summary
private CountingOutputStream currentOutputStream
fileBytesWrittenback to summary
private long fileBytesWritten
filesback to summary
private final List<SevenZArchiveEntry> files
finishedback to summary
private boolean finished
numNonEmptyStreamsback to summary
private int numNonEmptyStreams

Constructor Detail

SevenZOutputFileback to summary
public SevenZOutputFile(final File fileName) throws IOException

Opens file to write a 7z archive to.

Parameters
fileName:File

the file to write to

Exceptions
IOException:
if opening the file fails
SevenZOutputFileback to summary
public SevenZOutputFile(final File fileName, final char[] password) throws IOException

Opens file to write a 7z archive to.

Parameters
fileName:File

the file to write to

password:char[]

optional password if the archive has to be encrypted

Exceptions
IOException:
if opening the file fails
Since
1.23
SevenZOutputFileback to summary
public SevenZOutputFile(final SeekableByteChannel channel) throws IOException

Prepares channel to write a 7z archive to.

org.apache.commons.compress.utils.SeekableInMemoryByteChannel allows you to write to an in-memory archive.

Parameters
channel:SeekableByteChannel

the channel to write to

Exceptions
IOException:
if the channel cannot be positioned properly
Since
1.13
SevenZOutputFileback to summary
public SevenZOutputFile(final SeekableByteChannel channel, final char[] password) throws IOException

Prepares channel to write a 7z archive to.

org.apache.commons.compress.utils.SeekableInMemoryByteChannel allows you to write to an in-memory archive.

Parameters
channel:SeekableByteChannel

the channel to write to

password:char[]

optional password if the archive has to be encrypted

Exceptions
IOException:
if the channel cannot be positioned properly
Since
1.23

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Closes the archive, calling finish if necessary.

Annotations
@Override
Exceptions
IOException:
on error
closeArchiveEntryback to summary
public void closeArchiveEntry() throws IOException

Closes the archive entry.

Exceptions
IOException:
on error
createArchiveEntryback to summary
public SevenZArchiveEntry createArchiveEntry(final File inputFile, final String entryName)

Creates an archive entry using the inputFile and entryName provided.

Parameters
inputFile:File

file to create an entry from

entryName:String

the name to use

Returns:SevenZArchiveEntry

the ArchiveEntry set up with details from the file

createArchiveEntryback to summary
public SevenZArchiveEntry createArchiveEntry(final Path inputPath, final String entryName, final LinkOption... options) throws IOException

Creates an archive entry using the inputPath and entryName provided.

Parameters
inputPath:Path

path to create an entry from

entryName:String

the name to use

options:LinkOption[]

options indicating how symbolic links are handled.

Returns:SevenZArchiveEntry

the ArchiveEntry set up with details from the file

Exceptions
IOException:
on error
Since
1.21
fillDatesback to summary
private void fillDates(final Path inputPath, final SevenZArchiveEntry entry, final LinkOption... options) throws IOException
finishback to summary
public void finish() throws IOException

Finishes the addition of entries to this archive, without closing it.

Exceptions
IOException:
if archive is already closed.
getContentMethodsback to summary
private Iterable<? extends SevenZMethodConfiguration> getContentMethods(final SevenZArchiveEntry entry)
getCurrentOutputStreamback to summary
private OutputStream getCurrentOutputStream() throws IOException
putArchiveEntryback to summary
public void putArchiveEntry(final ArchiveEntry archiveEntry)

Records an archive entry to add. The caller must then write the content to the archive and call closeArchiveEntry() to complete the process.

Parameters
archiveEntry:ArchiveEntry

describes the entry

Annotations
@Deprecated
putArchiveEntryback to summary
public void putArchiveEntry(final SevenZArchiveEntry archiveEntry)

Records an archive entry to add. The caller must then write the content to the archive and call closeArchiveEntry() to complete the process.

Parameters
archiveEntry:SevenZArchiveEntry

describes the entry

Since
1.25.0
reverseback to summary
private static <T> Iterable<T> reverse(final Iterable<T> i)
setContentCompressionback to summary
public void setContentCompression(final SevenZMethod method)

Sets the default compression method to use for entry contents - the default is LZMA2.

Currently only SevenZMethod#COPY, SevenZMethod#LZMA2, SevenZMethod#BZIP2 and SevenZMethod#DEFLATE are supported.

This is a short form for passing a single-element iterable to setContentMethods.

Parameters
method:SevenZMethod

the default compression method

setContentMethodsback to summary
public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration> methods)

Sets the default (compression) methods to use for entry contents - the default is LZMA2.

Currently only SevenZMethod#COPY, SevenZMethod#LZMA2, SevenZMethod#BZIP2 and SevenZMethod#DEFLATE are supported.

The methods will be consulted in iteration order to create the final output.

Parameters
methods:Iterable<? extends SevenZMethodConfiguration>

the default (compression) methods

Since
1.8
setupFileOutputStreamback to summary
private CountingOutputStream setupFileOutputStream() throws IOException
writeback to summary
public void write(final byte[] b) throws IOException

Writes a byte array to the current archive entry.

Parameters
b:byte[]

The byte array to be written.

Exceptions
IOException:
on error
writeback to summary
public void write(final byte[] b, final int off, final int len) throws IOException

Writes part of a byte array to the current archive entry.

Parameters
b:byte[]

The byte array to be written.

off:int

offset into the array to start writing from

len:int

number of bytes to write

Exceptions
IOException:
on error
writeback to summary
public void write(final InputStream inputStream) throws IOException

Writes all of the given input stream to the current archive entry.

Parameters
inputStream:InputStream

the data source.

Exceptions
IOException:
if an I/O error occurs.
Since
1.21
writeback to summary
public void write(final int b) throws IOException

Writes a byte to the current archive entry.

Parameters
b:int

The byte to be written.

Exceptions
IOException:
on error
writeback to summary
public void write(final Path path, final OpenOption... options) throws IOException

Writes all of the given input stream to the current archive entry.

Parameters
path:Path

the data source.

options:OpenOption[]

options specifying how the file is opened.

Exceptions
IOException:
if an I/O error occurs.
Since
1.21
writeBitsback to summary
private void writeBits(final DataOutput header, final BitSet bits, final int length) throws IOException
writeFileAntiItemsback to summary
private void writeFileAntiItems(final DataOutput header) throws IOException
writeFileATimesback to summary
private void writeFileATimes(final DataOutput header) throws IOException
writeFileCTimesback to summary
private void writeFileCTimes(final DataOutput header) throws IOException
writeFileEmptyFilesback to summary
private void writeFileEmptyFiles(final DataOutput header) throws IOException
writeFileEmptyStreamsback to summary
private void writeFileEmptyStreams(final DataOutput header) throws IOException
writeFileMTimesback to summary
private void writeFileMTimes(final DataOutput header) throws IOException
writeFileNamesback to summary
private void writeFileNames(final DataOutput header) throws IOException
writeFilesInfoback to summary
private void writeFilesInfo(final DataOutput header) throws IOException
writeFileWindowsAttributesback to summary
private void writeFileWindowsAttributes(final DataOutput header) throws IOException
writeFolderback to summary
private void writeFolder(final DataOutput header, final SevenZArchiveEntry entry) throws IOException
writeHeaderback to summary
private void writeHeader(final DataOutput header) throws IOException
writePackInfoback to summary
private void writePackInfo(final DataOutput header) throws IOException
writeSingleCodecback to summary
private void writeSingleCodec(final SevenZMethodConfiguration m, final OutputStream bos) throws IOException
writeStreamsInfoback to summary
private void writeStreamsInfo(final DataOutput header) throws IOException
writeSubStreamsInfoback to summary
private void writeSubStreamsInfo(final DataOutput header) throws IOException
writeUint64back to summary
private void writeUint64(final DataOutput header, long value) throws IOException
writeUnpackInfoback to summary
private void writeUnpackInfo(final DataOutput header) throws IOException
org.apache.commons.compress.archivers.sevenz back to summary

private final Class SevenZOutputFile.OutputStreamWrapper

extends OutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final int
private final ByteBuffer

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.
public void
write(final byte[]
the data.
b
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
public void
write(final byte[]
the data.
b
,
final int
the start offset in the data.
off
,
final int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(final int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
Inherited from java.io.OutputStream:
nullOutputStream

Field Detail

BUF_SIZEback to summary
private static final int BUF_SIZE
bufferback to summary
private final ByteBuffer buffer

Constructor Detail

OutputStreamWrapperback to summary
private OutputStreamWrapper()

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(final byte[] b) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
b:byte[]

the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(final byte[] b, final int off, final int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeback to summary
public void write(final int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.