Class ZipSplitOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
ZipArchiveOutputStream when creating a split archive.- Since:
- 1.20
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FileChannelprivate longprivate intprivate booleanprivate FileRandomAccessOutputStreamprivate final byte[]private final longprivate longprivate static final longprivate static final long8.5.1 Capacities for split archives are as follows:private Path -
Constructor Summary
ConstructorsConstructorDescriptionZipSplitOutputStream(File zipFile, long splitSize) Creates a split ZIP.ZipSplitOutputStream(Path zipFile, long splitSize) Creates a split ZIP. -
Method Summary
Modifier and TypeMethodDescriptionlongcalculateDiskPosition(long disk, long localOffset) voidclose()private PathcreateNewSplitSegmentFile(Integer zipSplitSegmentSuffixIndex) Creates 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 .ziplongintprivate PathgetSplitSegmentFileName(Integer zipSplitSegmentSuffixIndex) private voidCreates a new ZIP split segment and prepare to write to the new segmentlongposition()Gets the current position in this stream.voidprepareToWriteUnsplittableContent(long unsplittableContentSize) Prepares to write unsplittable content.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) Writes 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) voidwriteAll(byte[] b, int off, int len, long atPosition) Writes all given bytes at a position.private voidwriteToSegment(Path segment, long position, byte[] b, int off, int len) private voidWrites the ZIP split signature (0x08074B50) to the head of the first ZIP split segmentMethods inherited from class org.apache.commons.compress.archivers.zip.RandomAccessOutputStream
writeAllMethods inherited from class java.io.OutputStream
flush
-
Field Details
-
ZIP_SEGMENT_MIN_SIZE
private static final long ZIP_SEGMENT_MIN_SIZE8.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:
-
ZIP_SEGMENT_MAX_SIZE
private static final long ZIP_SEGMENT_MAX_SIZE- See Also:
-
currentChannel
-
outputStream
-
zipFile
-
splitSize
private final long splitSize -
totalPosition
private long totalPosition -
currentSplitSegmentIndex
private int currentSplitSegmentIndex -
currentSplitSegmentBytesWritten
private long currentSplitSegmentBytesWritten -
finished
private boolean finished -
singleByte
private final byte[] singleByte -
diskToPosition
-
positionToFiles
-
-
Constructor Details
-
ZipSplitOutputStream
ZipSplitOutputStream(File zipFile, long splitSize) throws IllegalArgumentException, 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:
IllegalArgumentException- if arguments are illegal: Zip split segment size should between 64K and 4,294,967,295.IOException- if an I/O error occurs
-
ZipSplitOutputStream
ZipSplitOutputStream(Path zipFile, long splitSize) throws IllegalArgumentException, 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 to.splitSize- the split size.- Throws:
IllegalArgumentException- if arguments are illegal: Zip split segment size should between 64K and 4,294,967,295.IOException- if an I/O error occurs.- Since:
- 1.22
-
-
Method Details
-
calculateDiskPosition
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
createNewSplitSegmentFile
Creates 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:
IOException- if an I/O error occurs.
-
finish
The last ZIP split segment's suffix should be .zip- Throws:
IOException- if an I/O error occurs.
-
getCurrentSplitSegmentBytesWritten
public long getCurrentSplitSegmentBytesWritten() -
getCurrentSplitSegmentIndex
public int getCurrentSplitSegmentIndex() -
getSplitSegmentFileName
-
openNewSplitSegment
Creates a new ZIP split segment and prepare to write to the new segment- Throws:
IOException- if an I/O error occurs.
-
position
public long position()Description copied from class:RandomAccessOutputStreamGets the current position in this stream.- Specified by:
positionin classRandomAccessOutputStream- Returns:
- current position.
-
prepareToWriteUnsplittableContent
public void prepareToWriteUnsplittableContent(long unsplittableContentSize) throws IllegalArgumentException, IOException Prepares to write unsplittable content.Some data cannot 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- the split size request must be less than or equal to the the split size.- Throws:
IllegalArgumentException- if unsplittable content size is bigger than the split segment size.IOException- if an I/O error occurs.
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
Writes 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 classOutputStream- Parameters:
b- data to writeoff- offset of the start of data in param blen- the length of data to write- Throws:
IOException- if an I/O error occurs.
-
write
- Overrides:
writein classRandomAccessOutputStream- Throws:
IOException
-
writeAll
Description copied from class:RandomAccessOutputStreamWrites all given bytes at a position.- Specified by:
writeAllin classRandomAccessOutputStream- Parameters:
b- data to writeoff- offset of the start of data in param byteslen- the length of data to writeatPosition- position in the stream- Throws:
IOException- if an I/O error occurs.
-
writeToSegment
private void writeToSegment(Path segment, long position, byte[] b, int off, int len) throws IOException - Throws:
IOException
-
writeZipSplitSignature
Writes the ZIP split signature (0x08074B50) to the head of the first ZIP split segment- Throws:
IOException- if an I/O error occurs.
-