public class SevenZOutputFile
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
private class |
SevenZOutputFile.OutputStreamWrapper |
Modifier and Type | Field and Description |
---|---|
private CountingOutputStream[] |
additionalCountingStreams |
private java.util.Map<SevenZArchiveEntry,long[]> |
additionalSizes |
private java.nio.channels.SeekableByteChannel |
channel |
private java.util.zip.CRC32 |
compressedCrc32 |
private java.lang.Iterable<? extends SevenZMethodConfiguration> |
contentMethods |
private java.util.zip.CRC32 |
crc32 |
private CountingOutputStream |
currentOutputStream |
private long |
fileBytesWritten |
private java.util.List<SevenZArchiveEntry> |
files |
private boolean |
finished |
private int |
numNonEmptyStreams |
Constructor and Description |
---|
SevenZOutputFile(java.io.File filename)
Opens file to write a 7z archive to.
|
SevenZOutputFile(java.nio.channels.SeekableByteChannel channel)
Prepares channel to write a 7z archive to.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the archive, calling
finish() if necessary. |
void |
closeArchiveEntry()
Closes the archive entry.
|
SevenZArchiveEntry |
createArchiveEntry(java.io.File inputFile,
java.lang.String entryName)
Create an archive entry using the inputFile and entryName provided.
|
void |
finish()
Finishes the addition of entries to this archive, without closing it.
|
private java.lang.Iterable<? extends SevenZMethodConfiguration> |
getContentMethods(SevenZArchiveEntry entry) |
private java.io.OutputStream |
getCurrentOutputStream() |
void |
putArchiveEntry(ArchiveEntry archiveEntry)
Records an archive entry to add.
|
private static <T> java.lang.Iterable<T> |
reverse(java.lang.Iterable<T> i) |
void |
setContentCompression(SevenZMethod method)
Sets the default compression method to use for entry contents - the
default is LZMA2.
|
void |
setContentMethods(java.lang.Iterable<? extends SevenZMethodConfiguration> methods)
Sets the default (compression) methods to use for entry contents - the
default is LZMA2.
|
private CountingOutputStream |
setupFileOutputStream() |
void |
write(byte[] b)
Writes a byte array to the current archive entry.
|
void |
write(byte[] b,
int off,
int len)
Writes part of a byte array to the current archive entry.
|
void |
write(int b)
Writes a byte to the current archive entry.
|
private void |
writeBits(java.io.DataOutput header,
java.util.BitSet bits,
int length) |
private void |
writeFileAntiItems(java.io.DataOutput header) |
private void |
writeFileATimes(java.io.DataOutput header) |
private void |
writeFileCTimes(java.io.DataOutput header) |
private void |
writeFileEmptyFiles(java.io.DataOutput header) |
private void |
writeFileEmptyStreams(java.io.DataOutput header) |
private void |
writeFileMTimes(java.io.DataOutput header) |
private void |
writeFileNames(java.io.DataOutput header) |
private void |
writeFilesInfo(java.io.DataOutput header) |
private void |
writeFileWindowsAttributes(java.io.DataOutput header) |
private void |
writeFolder(java.io.DataOutput header,
SevenZArchiveEntry entry) |
private void |
writeHeader(java.io.DataOutput header) |
private void |
writePackInfo(java.io.DataOutput header) |
private void |
writeSingleCodec(SevenZMethodConfiguration m,
java.io.OutputStream bos) |
private void |
writeStreamsInfo(java.io.DataOutput header) |
private void |
writeSubStreamsInfo(java.io.DataOutput header) |
private void |
writeUint64(java.io.DataOutput header,
long value) |
private void |
writeUnpackInfo(java.io.DataOutput header) |
private final java.nio.channels.SeekableByteChannel channel
private final java.util.List<SevenZArchiveEntry> files
private int numNonEmptyStreams
private final java.util.zip.CRC32 crc32
private final java.util.zip.CRC32 compressedCrc32
private long fileBytesWritten
private boolean finished
private CountingOutputStream currentOutputStream
private CountingOutputStream[] additionalCountingStreams
private java.lang.Iterable<? extends SevenZMethodConfiguration> contentMethods
private final java.util.Map<SevenZArchiveEntry,long[]> additionalSizes
public SevenZOutputFile(java.io.File filename) throws java.io.IOException
filename
- the file to write tojava.io.IOException
- if opening the file failspublic SevenZOutputFile(java.nio.channels.SeekableByteChannel channel) throws java.io.IOException
SeekableInMemoryByteChannel
allows you to write to an in-memory archive.
channel
- the channel to write tojava.io.IOException
- if the channel cannot be positioned properlypublic void setContentCompression(SevenZMethod method)
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(java.lang.Iterable<? extends org.apache.commons.compress.archivers.sevenz.SevenZMethodConfiguration>)
.
method
- the default compression methodpublic void setContentMethods(java.lang.Iterable<? extends SevenZMethodConfiguration> methods)
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.
methods
- the default (compression) methodspublic void close() throws java.io.IOException
finish()
if necessary.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- on errorpublic SevenZArchiveEntry createArchiveEntry(java.io.File inputFile, java.lang.String entryName) throws java.io.IOException
inputFile
- file to create an entry fromentryName
- the name to usejava.io.IOException
- on errorpublic void putArchiveEntry(ArchiveEntry archiveEntry) throws java.io.IOException
closeArchiveEntry()
to complete the process.archiveEntry
- describes the entryjava.io.IOException
- on errorpublic void closeArchiveEntry() throws java.io.IOException
java.io.IOException
- on errorpublic void write(int b) throws java.io.IOException
b
- The byte to be written.java.io.IOException
- on errorpublic void write(byte[] b) throws java.io.IOException
b
- The byte array to be written.java.io.IOException
- on errorpublic void write(byte[] b, int off, int len) throws java.io.IOException
b
- The byte array to be written.off
- offset into the array to start writing fromlen
- number of bytes to writejava.io.IOException
- on errorpublic void finish() throws java.io.IOException
java.io.IOException
- if archive is already closed.private java.io.OutputStream getCurrentOutputStream() throws java.io.IOException
java.io.IOException
private CountingOutputStream setupFileOutputStream() throws java.io.IOException
java.io.IOException
private java.lang.Iterable<? extends SevenZMethodConfiguration> getContentMethods(SevenZArchiveEntry entry)
private void writeHeader(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeStreamsInfo(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writePackInfo(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeUnpackInfo(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFolder(java.io.DataOutput header, SevenZArchiveEntry entry) throws java.io.IOException
java.io.IOException
private void writeSingleCodec(SevenZMethodConfiguration m, java.io.OutputStream bos) throws java.io.IOException
java.io.IOException
private void writeSubStreamsInfo(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFilesInfo(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileEmptyStreams(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileEmptyFiles(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileAntiItems(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileNames(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileCTimes(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileATimes(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileMTimes(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeFileWindowsAttributes(java.io.DataOutput header) throws java.io.IOException
java.io.IOException
private void writeUint64(java.io.DataOutput header, long value) throws java.io.IOException
java.io.IOException
private void writeBits(java.io.DataOutput header, java.util.BitSet bits, int length) throws java.io.IOException
java.io.IOException
private static <T> java.lang.Iterable<T> reverse(java.lang.Iterable<T> i)