Top Description Fields Constructors Methods
org.apache.commons.compress.archivers.zip

pack-priv final Class ZipSplitOutputStream

extends RandomAccessOutputStream
Class Inheritance
Imports
java.io.File, .IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.nio.file.Files, .Path, .StandardCopyOption, .StandardOpenOption, java.util.ArrayList, .List, .Map, .Objects, .TreeMap, org.apache.commons.compress.utils.FileNameUtils

Used internally by ZipArchiveOutputStream when creating a split archive.
Since
1.20

Field Summary

Modifier and TypeField and Description
private FileChannel
private long
private int
private final List<Long>
private boolean
private FileRandomAccessOutputStream
private final TreeMap<Long, Path>
private final byte[]
private final long
private long
private static final long
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

private Path

Constructor Summary

AccessConstructor and Description
pack-priv
ZipSplitOutputStream(final File
the ZIP file to write to
zipFile
,
final long
the split size
splitSize
)

Creates a split ZIP.

pack-priv
ZipSplitOutputStream(final Path
the path to ZIP file to write to
zipFile
,
final long
the split size
splitSize
)

Creates a split ZIP.

Method Summary

Modifier and TypeMethod and Description
public long
calculateDiskPosition(final long disk, final long localOffset)

public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
private Path
createNewSplitSegmentFile(final 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 void
finish()

The last ZIP split segment's suffix should be .zip

public long
public int
private Path
getSplitSegmentFileName(final Integer zipSplitSegmentSuffixIndex)

private void
openNewSplitSegment()

Creates a new ZIP split segment and prepare to write to the new segment

public long
position()

Implements abstract org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.position.

Provides current position in output.
public void
prepareToWriteUnsplittableContent(final long unsplittableContentSize)

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.

public void
write(final byte[]
the data.
b
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
public void
write(final byte[]
data to write
b
,
final int
offset of the start of data in param b
off
,
final int
the length of data to write
len
)

Overrides java.io.OutputStream.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
public void
write(final int
the byte.
i
)

Overrides org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.write.

Writes the specified byte to this output stream.
public void
writeFully(final byte[]
data to write
b
,
final int
offset of the start of data in param b
off
,
final int
the length of data to write
len
,
final long
position in the stream
atPosition
)

Implements abstract org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.writeFully.

Writes given data to specific position.
private void
writeToSegment(final Path segment, final long position, final byte[] b, final int off, final int len)

private void
writeZipSplitSignature()

Writes the ZIP split signature (0x08074B50) to the head of the first ZIP split segment

Inherited from org.apache.commons.compress.archivers.zip.RandomAccessOutputStream:
writeFully

Field Detail

currentChannelback to summary
private FileChannel currentChannel
currentSplitSegmentBytesWrittenback to summary
private long currentSplitSegmentBytesWritten
currentSplitSegmentIndexback to summary
private int currentSplitSegmentIndex
diskToPositionback to summary
private final List<Long> diskToPosition
finishedback to summary
private boolean finished
outputStreamback to summary
private FileRandomAccessOutputStream outputStream
positionToFilesback to summary
private final TreeMap<Long, Path> positionToFiles
singleByteback to summary
private final byte[] singleByte
splitSizeback to summary
private final long splitSize
totalPositionback to summary
private long totalPosition
ZIP_SEGMENT_MAX_SIZEback to summary
private static final long ZIP_SEGMENT_MAX_SIZE
ZIP_SEGMENT_MIN_SIZEback to summary
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

zipFileback to summary
private Path zipFile

Constructor Detail

ZipSplitOutputStreamback to summary
pack-priv ZipSplitOutputStream(final File zipFile, final 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:File

the ZIP file to write to

splitSize:long

the split size

Exceptions
IllegalArgumentException:
if arguments are illegal: Zip split segment size should between 64K and 4,294,967,295.
IOException:
if an I/O error occurs
ZipSplitOutputStreamback to summary
pack-priv ZipSplitOutputStream(final Path zipFile, final 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:Path

the path to ZIP file to write to

splitSize:long

the split size

Exceptions
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 Detail

calculateDiskPositionback to summary
public long calculateDiskPosition(final long disk, final long localOffset) throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
createNewSplitSegmentFileback to summary
private Path createNewSplitSegmentFile(final Integer zipSplitSegmentSuffixIndex) throws IOException

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), .zip

8.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)

finishback to summary
private void finish() throws IOException

The last ZIP split segment's suffix should be .zip

getCurrentSplitSegmentBytesWrittenback to summary
public long getCurrentSplitSegmentBytesWritten()
getCurrentSplitSegmentIndexback to summary
public int getCurrentSplitSegmentIndex()
getSplitSegmentFileNameback to summary
private Path getSplitSegmentFileName(final Integer zipSplitSegmentSuffixIndex)
openNewSplitSegmentback to summary
private void openNewSplitSegment() throws IOException

Creates a new ZIP split segment and prepare to write to the new segment

positionback to summary
public long position()

Implements abstract org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.position.

Doc from org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.position.

Provides current position in output.

Returns:long

current position.

Annotations
@Override
prepareToWriteUnsplittableContentback to summary
public void prepareToWriteUnsplittableContent(final long unsplittableContentSize) throws IllegalArgumentException, 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.

writeback to summary
public void write(final byte[] b) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
b:byte[]

the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(final byte[] b, final int off, final int len) throws IOException

Overrides java.io.OutputStream.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

Parameters
b:byte[]

data to write

off:int

offset of the start of data in param b

len:int

the length of data to write

Annotations
@Override
Exceptions
IOException:

Doc from java.io.OutputStream.write.

if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

writeback to summary
public void write(final int i) throws IOException

Overrides org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
i:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeFullyback to summary
public void writeFully(final byte[] b, final int off, final int len, final long atPosition) throws IOException

Implements abstract org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.writeFully.

Doc from org.apache.commons.compress.archivers.zip.RandomAccessOutputStream.writeFully.

Writes given data to specific position.

Parameters
b:byte[]

data to write

off:int

offset of the start of data in param b

len:int

the length of data to write

atPosition:long

position in the stream

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeToSegmentback to summary
private void writeToSegment(final Path segment, final long position, final byte[] b, final int off, final int len) throws IOException
writeZipSplitSignatureback to summary
private void writeZipSplitSignature() throws IOException

Writes the ZIP split signature (0x08074B50) to the head of the first ZIP split segment