Class ZipSplitOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.commons.compress.archivers.zip.ZipSplitOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
class ZipSplitOutputStream extends java.io.OutputStreamUsed internally byZipArchiveOutputStreamwhen creating a split archive.- Since:
- 1.20
-
-
Field Summary
Fields Modifier and Type Field Description private longcurrentSplitSegmentBytesWrittenprivate intcurrentSplitSegmentIndexprivate booleanfinishedprivate java.io.OutputStreamoutputStreamprivate byte[]singleByteprivate longsplitSizeprivate static longZIP_SEGMENT_MAX_SIZEprivate static longZIP_SEGMENT_MIN_SIZE8.5.1 Capacities for split archives are as follows:private java.io.FilezipFile
-
Constructor Summary
Constructors Constructor Description ZipSplitOutputStream(java.io.File zipFile, long splitSize)Create a split zip.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private java.io.FilecreateNewSplitSegmentFile(java.lang.Integer zipSplitSegmentSuffixIndex)Create the new zip split segment, the last zip segment should be .zip, and the zip split segments' suffix should be like .z01, .z02, .z03, ...private voidfinish()The last zip split segment's suffix should be .ziplonggetCurrentSplitSegmentBytesWritten()intgetCurrentSplitSegmentIndex()private voidopenNewSplitSegment()Create a new zip split segment and prepare to write to the new segmentvoidprepareToWriteUnsplittableContent(long unsplittableContentSize)Some data can not be written to different split segments, for example:voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)Write the data to zip split segments, if the remaining space of current split segment is not enough, then a new split segment should be createdvoidwrite(int i)private voidwriteZipSplitSignature()Write the zip split signature (0x08074B50) to the head of the first zip split segment
-
-
-
Field Detail
-
outputStream
private java.io.OutputStream outputStream
-
zipFile
private java.io.File zipFile
-
splitSize
private final long splitSize
-
currentSplitSegmentIndex
private int currentSplitSegmentIndex
-
currentSplitSegmentBytesWritten
private long currentSplitSegmentBytesWritten
-
finished
private boolean finished
-
singleByte
private final byte[] singleByte
-
ZIP_SEGMENT_MIN_SIZE
private static final long ZIP_SEGMENT_MIN_SIZE
8.5.1 Capacities for split archives are as follows:Maximum number of segments = 4,294,967,295 - 1 Maximum .ZIP segment size = 4,294,967,295 bytes (refer to section 8.5.6) Minimum segment size = 64K Maximum PKSFX segment size = 2,147,483,647 bytes
- See Also:
- Constant Field Values
-
ZIP_SEGMENT_MAX_SIZE
private static final long ZIP_SEGMENT_MAX_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ZipSplitOutputStream
public ZipSplitOutputStream(java.io.File zipFile, long splitSize) throws java.lang.IllegalArgumentException, java.io.IOExceptionCreate a split zip. If the zip file is smaller than the split size, then there will only be one split zip, and its suffix is .zip, otherwise the split segments should be like .z01, .z02, ... .z(N-1), .zip- Parameters:
zipFile- the zip file to write tosplitSize- the split size- Throws:
java.lang.IllegalArgumentExceptionjava.io.IOException
-
-
Method Detail
-
prepareToWriteUnsplittableContent
public void prepareToWriteUnsplittableContent(long unsplittableContentSize) throws java.lang.IllegalArgumentException, java.io.IOExceptionSome data can not be written to different split segments, for example:4.4.1.5 The end of central directory record and the Zip64 end of central directory locator record MUST reside on the same disk when splitting or spanning an archive.
- Parameters:
unsplittableContentSize-- Throws:
java.lang.IllegalArgumentExceptionjava.io.IOException
-
write
public void write(int i) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOExceptionWrite the data to zip split segments, if the remaining space of current split segment is not enough, then a new split segment should be created- Overrides:
writein classjava.io.OutputStream- Parameters:
b- data to writeoff- offset of the start of data in param blen- the length of data to write- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
finish
private void finish() throws java.io.IOExceptionThe last zip split segment's suffix should be .zip- Throws:
java.io.IOException
-
openNewSplitSegment
private void openNewSplitSegment() throws java.io.IOExceptionCreate a new zip split segment and prepare to write to the new segment- Throws:
java.io.IOException
-
writeZipSplitSignature
private void writeZipSplitSignature() throws java.io.IOExceptionWrite the zip split signature (0x08074B50) to the head of the first zip split segment- Throws:
java.io.IOException
-
createNewSplitSegmentFile
private java.io.File createNewSplitSegmentFile(java.lang.Integer zipSplitSegmentSuffixIndex) throws java.io.IOExceptionCreate the new zip split segment, the last zip segment should be .zip, and the zip split segments' suffix should be like .z01, .z02, .z03, ... .z99, .z100, ..., .z(N-1), .zip8.3.3 Split ZIP files are typically written to the same location and are subject to name collisions if the spanned name format is used since each segment will reside on the same drive. To avoid name collisions, split archives are named as follows.
Segment 1 = filename.z01 Segment n-1 = filename.z(n-1) Segment n = filename.zip
NOTE: The zip split segment begin from 1,2,3,... , and we're creating a new segment, so the new segment suffix should be (currentSplitSegmentIndex + 2)
- Parameters:
zipSplitSegmentSuffixIndex-- Returns:
- Throws:
java.io.IOException
-
getCurrentSplitSegmentIndex
public int getCurrentSplitSegmentIndex()
-
getCurrentSplitSegmentBytesWritten
public long getCurrentSplitSegmentBytesWritten()
-
-