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
final class ZipSplitOutputStream extends java.io.OutputStream
Used internally byZipArchiveOutputStream
when creating a split archive.- Since:
- 1.20
-
-
Field Summary
Fields Modifier and Type Field Description private long
currentSplitSegmentBytesWritten
private int
currentSplitSegmentIndex
private boolean
finished
private java.io.OutputStream
outputStream
private byte[]
singleByte
private long
splitSize
private static long
ZIP_SEGMENT_MAX_SIZE
private static long
ZIP_SEGMENT_MIN_SIZE
8.5.1 Capacities for split archives are as follows:private java.nio.file.Path
zipFile
-
Constructor Summary
Constructors Constructor Description ZipSplitOutputStream(java.io.File zipFile, long splitSize)
Creates a split ZIP.ZipSplitOutputStream(java.nio.file.Path zipFile, long splitSize)
Creates a split ZIP.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private java.nio.file.Path
createNewSplitSegmentFile(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 void
finish()
The last ZIP split segment's suffix should be .ziplong
getCurrentSplitSegmentBytesWritten()
int
getCurrentSplitSegmentIndex()
private void
openNewSplitSegment()
Create a new ZIP split segment and prepare to write to the new segmentvoid
prepareToWriteUnsplittableContent(long unsplittableContentSize)
Some data can not be written to different split segments, for example:void
write(byte[] b)
void
write(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 createdvoid
write(int i)
private void
writeZipSplitSignature()
Write the ZIP split signature (0x08074B50) to the head of the first ZIP split segment
-
-
-
Field Detail
-
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
-
outputStream
private java.io.OutputStream outputStream
-
zipFile
private java.nio.file.Path zipFile
-
splitSize
private final long splitSize
-
currentSplitSegmentIndex
private int currentSplitSegmentIndex
-
currentSplitSegmentBytesWritten
private long currentSplitSegmentBytesWritten
-
finished
private boolean finished
-
singleByte
private final byte[] singleByte
-
-
Constructor Detail
-
ZipSplitOutputStream
public ZipSplitOutputStream(java.io.File zipFile, long splitSize) throws java.lang.IllegalArgumentException, java.io.IOException
Creates 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.IllegalArgumentException
- if arguments are illegal: Zip split segment size should between 64K and 4,294,967,295.java.io.IOException
- if an I/O error occurs
-
ZipSplitOutputStream
public ZipSplitOutputStream(java.nio.file.Path zipFile, long splitSize) throws java.lang.IllegalArgumentException, java.io.IOException
Creates 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 path to ZIP file to write tosplitSize
- the split size- Throws:
java.lang.IllegalArgumentException
- if arguments are illegal: Zip split segment size should between 64K and 4,294,967,295.java.io.IOException
- if an I/O error occurs- Since:
- 1.22
-
-
Method Detail
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
createNewSplitSegmentFile
private java.nio.file.Path createNewSplitSegmentFile(java.lang.Integer zipSplitSegmentSuffixIndex) throws java.io.IOException
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, ... .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
-
finish
private void finish() throws java.io.IOException
The last ZIP split segment's suffix should be .zip- Throws:
java.io.IOException
-
getCurrentSplitSegmentBytesWritten
public long getCurrentSplitSegmentBytesWritten()
-
getCurrentSplitSegmentIndex
public int getCurrentSplitSegmentIndex()
-
openNewSplitSegment
private void openNewSplitSegment() throws java.io.IOException
Create a new ZIP split segment and prepare to write to the new segment- Throws:
java.io.IOException
-
prepareToWriteUnsplittableContent
public void prepareToWriteUnsplittableContent(long unsplittableContentSize) throws java.lang.IllegalArgumentException, java.io.IOException
Some 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.IllegalArgumentException
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
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 created- Overrides:
write
in 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
-
write
public void write(int i) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
writeZipSplitSignature
private void writeZipSplitSignature() throws java.io.IOException
Write the ZIP split signature (0x08074B50) to the head of the first ZIP split segment- Throws:
java.io.IOException
-
-