Package kala.compress.archivers.sevenz
Class SevenZArchiveWriter
- java.lang.Object
-
- kala.compress.archivers.sevenz.SevenZArchiveWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class SevenZArchiveWriter extends java.lang.Object implements java.io.CloseableWrites a 7z file.- Since:
- 1.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSevenZArchiveWriter.OutputStreamWrapper
-
Field Summary
Fields Modifier and Type Field Description private CountingOutputStream[]additionalCountingStreamsprivate java.util.Map<SevenZArchiveEntry,long[]>additionalSizesprivate AES256Optionsaes256Optionsprivate java.nio.channels.SeekableByteChannelchannelprivate java.util.zip.CRC32compressedCrc32private java.lang.Iterable<? extends SevenZMethodConfiguration>contentMethodsprivate java.util.zip.CRC32crc32private CountingOutputStreamcurrentOutputStreamprivate longfileBytesWrittenprivate java.util.List<SevenZArchiveEntry>filesprivate booleanfinishedprivate intnumNonEmptyStreams
-
Constructor Summary
Constructors Constructor Description SevenZArchiveWriter(java.nio.channels.SeekableByteChannel channel)Prepares channel to write a 7z archive to.SevenZArchiveWriter(java.nio.channels.SeekableByteChannel channel, char[] password)Prepares channel to write a 7z archive to.SevenZArchiveWriter(java.nio.file.Path file)Opens file to write a 7z archive to.SevenZArchiveWriter(java.nio.file.Path file, char[] password)Opens file to write a 7z archive to.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the archive, callingfinish()if necessary.voidcloseArchiveEntry()Closes the archive entry.SevenZArchiveEntrycreateArchiveEntry(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options)Creates an archive entry using the inputPath and entryName provided.private voidfillTimes(java.nio.file.Path inputPath, SevenZArchiveEntry entry, java.nio.file.LinkOption... options)voidfinish()Finishes the addition of entries to this archive, without closing it.private java.lang.Iterable<? extends SevenZMethodConfiguration>getContentMethods(SevenZArchiveEntry entry)private java.io.OutputStreamgetCurrentOutputStream()voidputArchiveEntry(SevenZArchiveEntry archiveEntry)Records an archive entry to add.private static <T> java.lang.Iterable<T>reverse(java.lang.Iterable<T> i)voidsetContentCompression(SevenZMethod method)Sets the default compression method to use for entry contents - the default is LZMA2.voidsetContentMethods(java.lang.Iterable<? extends SevenZMethodConfiguration> methods)Sets the default (compression) methods to use for entry contents - the default is LZMA2.private CountingOutputStreamsetupFileOutputStream()voidwrite(byte[] b)Writes a byte array to the current archive entry.voidwrite(byte[] b, int off, int len)Writes part of a byte array to the current archive entry.voidwrite(int b)Writes a byte to the current archive entry.voidwrite(java.io.InputStream inputStream)Writes all of the given input stream to the current archive entry.voidwrite(java.nio.file.Path path, java.nio.file.OpenOption... options)Writes all of the given input stream to the current archive entry.private voidwriteBits(java.io.DataOutput header, java.util.BitSet bits, int length)private voidwriteFileAntiItems(java.io.DataOutput header)private voidwriteFileATimes(java.io.DataOutput header)private voidwriteFileCTimes(java.io.DataOutput header)private voidwriteFileEmptyFiles(java.io.DataOutput header)private voidwriteFileEmptyStreams(java.io.DataOutput header)private voidwriteFileMTimes(java.io.DataOutput header)private voidwriteFileNames(java.io.DataOutput header)private voidwriteFilesInfo(java.io.DataOutput header)private voidwriteFileWindowsAttributes(java.io.DataOutput header)private voidwriteFolder(java.io.DataOutput header, SevenZArchiveEntry entry)private voidwriteHeader(java.io.DataOutput header)private voidwritePackInfo(java.io.DataOutput header)private voidwriteSingleCodec(SevenZMethodConfiguration m, java.io.OutputStream bos)private voidwriteStreamsInfo(java.io.DataOutput header)private voidwriteSubStreamsInfo(java.io.DataOutput header)private voidwriteUint64(java.io.DataOutput header, long value)private voidwriteUnpackInfo(java.io.DataOutput header)
-
-
-
Field Detail
-
channel
private final java.nio.channels.SeekableByteChannel channel
-
files
private final java.util.List<SevenZArchiveEntry> files
-
numNonEmptyStreams
private int numNonEmptyStreams
-
crc32
private final java.util.zip.CRC32 crc32
-
compressedCrc32
private final java.util.zip.CRC32 compressedCrc32
-
fileBytesWritten
private long fileBytesWritten
-
finished
private boolean finished
-
currentOutputStream
private CountingOutputStream currentOutputStream
-
additionalCountingStreams
private CountingOutputStream[] additionalCountingStreams
-
contentMethods
private java.lang.Iterable<? extends SevenZMethodConfiguration> contentMethods
-
additionalSizes
private final java.util.Map<SevenZArchiveEntry,long[]> additionalSizes
-
aes256Options
private AES256Options aes256Options
-
-
Constructor Detail
-
SevenZArchiveWriter
public SevenZArchiveWriter(java.nio.file.Path file) throws java.io.IOExceptionOpens file to write a 7z archive to.- Parameters:
file- the file to write to- Throws:
java.io.IOException- if opening the file fails- Since:
- 1.27.1-0
-
SevenZArchiveWriter
public SevenZArchiveWriter(java.nio.file.Path file, char[] password) throws java.io.IOExceptionOpens file to write a 7z archive to.- Parameters:
file- the file to write topassword- optional password if the archive has to be encrypted- Throws:
java.io.IOException- if opening the file fails- Since:
- 1.27.1-0
-
SevenZArchiveWriter
public SevenZArchiveWriter(java.nio.channels.SeekableByteChannel channel) throws java.io.IOExceptionPrepares channel to write a 7z archive to.SeekableInMemoryByteChannelallows you to write to an in-memory archive.- Parameters:
channel- the channel to write to- Throws:
java.io.IOException- if the channel cannot be positioned properly- Since:
- 1.13
-
SevenZArchiveWriter
public SevenZArchiveWriter(java.nio.channels.SeekableByteChannel channel, char[] password) throws java.io.IOExceptionPrepares channel to write a 7z archive to.SeekableInMemoryByteChannelallows you to write to an in-memory archive.- Parameters:
channel- the channel to write topassword- optional password if the archive has to be encrypted- Throws:
java.io.IOException- if the channel cannot be positioned properly- Since:
- 1.23
-
-
Method Detail
-
reverse
private static <T> java.lang.Iterable<T> reverse(java.lang.Iterable<T> i)
-
close
public void close() throws java.io.IOExceptionCloses the archive, callingfinish()if necessary.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- on error
-
closeArchiveEntry
public void closeArchiveEntry() throws java.io.IOExceptionCloses the archive entry.- Throws:
java.io.IOException- on error
-
createArchiveEntry
public SevenZArchiveEntry createArchiveEntry(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options) throws java.io.IOException
Creates an archive entry using the inputPath and entryName provided.- Parameters:
inputPath- path to create an entry fromentryName- the name to useoptions- options indicating how symbolic links are handled.- Returns:
- the ArchiveEntry set up with details from the file
- Throws:
java.io.IOException- on error- Since:
- 1.21
-
fillTimes
private void fillTimes(java.nio.file.Path inputPath, SevenZArchiveEntry entry, java.nio.file.LinkOption... options) throws java.io.IOException- Throws:
java.io.IOException
-
finish
public void finish() throws java.io.IOExceptionFinishes the addition of entries to this archive, without closing it.- Throws:
java.io.IOException- if archive is already closed.
-
getContentMethods
private java.lang.Iterable<? extends SevenZMethodConfiguration> getContentMethods(SevenZArchiveEntry entry)
-
getCurrentOutputStream
private java.io.OutputStream getCurrentOutputStream() throws java.io.IOException- Throws:
java.io.IOException
-
putArchiveEntry
public void putArchiveEntry(SevenZArchiveEntry archiveEntry)
Records an archive entry to add. The caller must then write the content to the archive and callcloseArchiveEntry()to complete the process.- Parameters:
archiveEntry- describes the entry- Since:
- 1.25.0
-
setContentCompression
public void setContentCompression(SevenZMethod method)
Sets the default compression method to use for entry contents - the default is LZMA2.Currently only
SevenZMethod.COPY,SevenZMethod.LZMA2,SevenZMethod.BZIP2andSevenZMethod.DEFLATEare supported.This is a short form for passing a single-element iterable to
setContentMethods(java.lang.Iterable<? extends kala.compress.archivers.sevenz.SevenZMethodConfiguration>).- Parameters:
method- the default compression method
-
setContentMethods
public void setContentMethods(java.lang.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.BZIP2andSevenZMethod.DEFLATEare supported.The methods will be consulted in iteration order to create the final output.
- Parameters:
methods- the default (compression) methods- Since:
- 1.8
-
setupFileOutputStream
private CountingOutputStream setupFileOutputStream() throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOExceptionWrites a byte array to the current archive entry.- Parameters:
b- The byte array to be written.- Throws:
java.io.IOException- on error
-
write
public void write(byte[] b, int off, int len) throws java.io.IOExceptionWrites part of a byte array to the current archive entry.- Parameters:
b- The byte array to be written.off- offset into the array to start writing fromlen- number of bytes to write- Throws:
java.io.IOException- on error
-
write
public void write(java.io.InputStream inputStream) throws java.io.IOExceptionWrites all of the given input stream to the current archive entry.- Parameters:
inputStream- the data source.- Throws:
java.io.IOException- if an I/O error occurs.- Since:
- 1.21
-
write
public void write(int b) throws java.io.IOExceptionWrites a byte to the current archive entry.- Parameters:
b- The byte to be written.- Throws:
java.io.IOException- on error
-
write
public void write(java.nio.file.Path path, java.nio.file.OpenOption... options) throws java.io.IOExceptionWrites all of the given input stream to the current archive entry.- Parameters:
path- the data source.options- options specifying how the file is opened.- Throws:
java.io.IOException- if an I/O error occurs.- Since:
- 1.21
-
writeBits
private void writeBits(java.io.DataOutput header, java.util.BitSet bits, int length) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileAntiItems
private void writeFileAntiItems(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileATimes
private void writeFileATimes(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileCTimes
private void writeFileCTimes(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileEmptyFiles
private void writeFileEmptyFiles(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileEmptyStreams
private void writeFileEmptyStreams(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileMTimes
private void writeFileMTimes(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileNames
private void writeFileNames(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFilesInfo
private void writeFilesInfo(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFileWindowsAttributes
private void writeFileWindowsAttributes(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeFolder
private void writeFolder(java.io.DataOutput header, SevenZArchiveEntry entry) throws java.io.IOException- Throws:
java.io.IOException
-
writeHeader
private void writeHeader(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writePackInfo
private void writePackInfo(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeSingleCodec
private void writeSingleCodec(SevenZMethodConfiguration m, java.io.OutputStream bos) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStreamsInfo
private void writeStreamsInfo(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeSubStreamsInfo
private void writeSubStreamsInfo(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint64
private void writeUint64(java.io.DataOutput header, long value) throws java.io.IOException- Throws:
java.io.IOException
-
writeUnpackInfo
private void writeUnpackInfo(java.io.DataOutput header) throws java.io.IOException- Throws:
java.io.IOException
-
-