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

public Class ZipSplitReadOnlySeekableByteChannel

extends MultiReadOnlySeekableByteChannel
Class Inheritance
Imports
java.io.File, .IOException, .Serializable, java.nio.ByteBuffer, java.nio.channels.SeekableByteChannel, java.nio.file.Files, .OpenOption, .Path, .StandardOpenOption, java.util.ArrayList, .Arrays, .Comparator, .List, .Objects, java.util.regex.Pattern, java.util.stream.Collectors, .Stream, org.apache.commons.compress.archivers.ArchiveStreamFactory, org.apache.commons.compress.utils.FileNameUtils, .MultiReadOnlySeekableByteChannel

MultiReadOnlySeekableByteChannel that knows what a split ZIP archive should look like.

If you want to read a split archive using ZipFile then create an instance of this class from the parts of the archive.

Since
1.20

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Path[]
private static final int
private final ByteBuffer

Constructor Summary

AccessConstructor and Description
public
ZipSplitReadOnlySeekableByteChannel(final List<SeekableByteChannel>
the channels to concatenate
channels
)

Concatenates the given channels.

Method Summary

Modifier and TypeMethod and Description
private void
assertSplitSignature(final List<SeekableByteChannel>
channels to be validated
channels
)

Based on the ZIP specification:

8.5.3 Spanned/Split archives created using PKZIP for Windows (V2.50 or greater), PKZIP Command Line (V2.50 or greater), or PKZIP Explorer will include a special spanning signature as the first 4 bytes of the first segment of the archive.

public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all ZIP split files
buildFromLastSplitSegment
(final File
the last segment of ZIP split files, note that the extension SHOULD be .zip
lastSegmentFile
)

Concatenates ZIP split files from the last segment(the extension SHOULD be .zip)

public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all ZIP split files
buildFromLastSplitSegment
(final Path
the last segment of ZIP split files, note that the extension MUST be .zip
lastSegmentPath
)

Concatenates ZIP split files from the last segment (the extension MUST be .zip)

public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all provided files
forFiles
(final File...
the files to concatenate, note that the LAST FILE of files should be the LAST SEGMENT(.zip) and these files should be added in correct order (e.g. .z01, .z02... .z99, .zip)
files
)

Hides org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel.forFiles.

Concatenates the given files.
public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all provided files
forFiles
(final File
the last segment of split ZIP segments, its extension should be .zip
lastSegmentFile
,
final Iterable<File>
the files to concatenate except for the last segment, note these files should be added in correct order (e.g. .z01, .z02... .z99)
files
)

Concatenates the given files.

public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all provided channels
forOrderedSeekableByteChannels
(final SeekableByteChannel...
the channels to concatenate, note that the LAST CHANNEL of channels should be the LAST SEGMENT(.zip) and these channels should be added in correct order (e.g. .z01, .z02... .z99, .zip)
channels
)

Concatenates the given channels.

public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all provided channels
forOrderedSeekableByteChannels
(final SeekableByteChannel
channel of the last segment of split ZIP segments, its extension should be .zip
lastSegmentChannel
,
final Iterable<SeekableByteChannel>
the channels to concatenate except for the last segment, note these channels should be added in correct order (e.g. .z01, .z02... .z99)
channels
)

Concatenates the given channels.

public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all provided files
forPaths
(final List<Path>
the file paths to concatenate, note that the LAST FILE of files should be the LAST SEGMENT(.zip) and these files should be added in correct order (e.g.: .z01, .z02... .z99, .zip)
paths
,
final OpenOption[]
the options to open paths (shared by all paths).
openOptions
)

Concatenates the given file paths.

public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all provided files
forPaths
(final Path...
the file paths to concatenate, note that the LAST FILE of files should be the LAST SEGMENT(.zip) and these files should be added in correct order (e.g.: .z01, .z02... .z99, .zip)
paths
)

Hides org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel.forPaths.

Concatenates the given file paths.
public static SeekableByteChannel

Returns:

SeekableByteChannel that concatenates all provided files
forPaths
(final Path
the last segment path of split ZIP segments, its extension must be .zip
lastSegmentPath
,
final Iterable<Path>
the file paths to concatenate except for the last segment, note these files should be added in correct order (e.g.: .z01, .z02... .z99)
paths
)

Concatenates the given file paths.

Inherited from org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel:
closeforSeekableByteChannelsisOpenpositionpositionpositionreadsizetruncatewrite

Field Detail

EMPTY_PATH_ARRAYback to summary
private static final Path[] EMPTY_PATH_ARRAY

Hides org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel.EMPTY_PATH_ARRAY.

ZIP_SPLIT_SIGNATURE_LENGTHback to summary
private static final int ZIP_SPLIT_SIGNATURE_LENGTH
zipSplitSignatureByteBufferback to summary
private final ByteBuffer zipSplitSignatureByteBuffer

Constructor Detail

ZipSplitReadOnlySeekableByteChannelback to summary
public ZipSplitReadOnlySeekableByteChannel(final List<SeekableByteChannel> channels) throws IOException

Concatenates the given channels.

The channels should be add in ascending order, e.g. z01, z02, ... z99, ZIP please note that the .zip file is the last segment and should be added as the last one in the channels

Parameters
channels:List<SeekableByteChannel>

the channels to concatenate

Exceptions
IOException:
if the first channel doesn't seem to hold the beginning of a split archive
NullPointerException:
if channels is null

Method Detail

assertSplitSignatureback to summary
private void assertSplitSignature(final List<SeekableByteChannel> channels) throws IOException

Based on the ZIP specification:

8.5.3 Spanned/Split archives created using PKZIP for Windows (V2.50 or greater), PKZIP Command Line (V2.50 or greater), or PKZIP Explorer will include a special spanning signature as the first 4 bytes of the first segment of the archive. This signature (0x08074b50) will be followed immediately by the local header signature for the first file in the archive.

The first 4 bytes of the first ZIP split segment should be the ZIP split signature(0x08074B50)

Parameters
channels:List<SeekableByteChannel>

channels to be validated

buildFromLastSplitSegmentback to summary
public static SeekableByteChannel buildFromLastSplitSegment(final File lastSegmentFile) throws IOException

Concatenates ZIP split files from the last segment(the extension SHOULD be .zip)

Parameters
lastSegmentFile:File

the last segment of ZIP split files, note that the extension SHOULD be .zip

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all ZIP split files

Exceptions
IOException:
if the first channel doesn't seem to hold the beginning of a split archive
IllegalArgumentException:
if the lastSegmentFile's extension is NOT .zip
buildFromLastSplitSegmentback to summary
public static SeekableByteChannel buildFromLastSplitSegment(final Path lastSegmentPath) throws IOException

Concatenates ZIP split files from the last segment (the extension MUST be .zip)

Parameters
lastSegmentPath:Path

the last segment of ZIP split files, note that the extension MUST be .zip

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all ZIP split files

Exceptions
IOException:
if the first channel doesn't seem to hold the beginning of a split archive
IllegalArgumentException:
if the lastSegmentPath's extension is NOT .zip
Since
1.22
forFilesback to summary
public static SeekableByteChannel forFiles(final File... files) throws IOException

Hides org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel.forFiles.

Concatenates the given files.

Parameters
files:File[]

the files to concatenate, note that the LAST FILE of files should be the LAST SEGMENT(.zip) and these files should be added in correct order (e.g. .z01, .z02... .z99, .zip)

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all provided files

Exceptions
IOException:
  • if opening a channel for one of the files fails
  • if the first channel doesn't seem to hold the beginning of a split archive
NullPointerException:
if files is null
forFilesback to summary
public static SeekableByteChannel forFiles(final File lastSegmentFile, final Iterable<File> files) throws IOException

Concatenates the given files.

Parameters
lastSegmentFile:File

the last segment of split ZIP segments, its extension should be .zip

files:Iterable<File>

the files to concatenate except for the last segment, note these files should be added in correct order (e.g. .z01, .z02... .z99)

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all provided files

Exceptions
IOException:
if the first channel doesn't seem to hold the beginning of a split archive
NullPointerException:
if files or lastSegmentFile is null
forOrderedSeekableByteChannelsback to summary
public static SeekableByteChannel forOrderedSeekableByteChannels(final SeekableByteChannel... channels) throws IOException

Concatenates the given channels.

Parameters
channels:SeekableByteChannel[]

the channels to concatenate, note that the LAST CHANNEL of channels should be the LAST SEGMENT(.zip) and these channels should be added in correct order (e.g. .z01, .z02... .z99, .zip)

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all provided channels

Exceptions
IOException:
if reading channels fails
NullPointerException:
if channels is null
forOrderedSeekableByteChannelsback to summary
public static SeekableByteChannel forOrderedSeekableByteChannels(final SeekableByteChannel lastSegmentChannel, final Iterable<SeekableByteChannel> channels) throws IOException

Concatenates the given channels.

Parameters
lastSegmentChannel:SeekableByteChannel

channel of the last segment of split ZIP segments, its extension should be .zip

channels:Iterable<SeekableByteChannel>

the channels to concatenate except for the last segment, note these channels should be added in correct order (e.g. .z01, .z02... .z99)

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all provided channels

Exceptions
IOException:
if the first channel doesn't seem to hold the beginning of a split archive
NullPointerException:
if lastSegmentChannel or channels is null
forPathsback to summary
public static SeekableByteChannel forPaths(final List<Path> paths, final OpenOption[] openOptions) throws IOException

Concatenates the given file paths.

Parameters
paths:List<Path>

the file paths to concatenate, note that the LAST FILE of files should be the LAST SEGMENT(.zip) and these files should be added in correct order (e.g.: .z01, .z02... .z99, .zip)

openOptions:OpenOption[]

the options to open paths (shared by all paths).

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all provided files

Exceptions
IOException:
  • if opening a channel for one of the files fails
  • if the first channel doesn't seem to hold the beginning of a split archive
NullPointerException:
if files is null
Since
1.22
forPathsback to summary
public static SeekableByteChannel forPaths(final Path... paths) throws IOException

Hides org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel.forPaths.

Concatenates the given file paths.

Parameters
paths:Path[]

the file paths to concatenate, note that the LAST FILE of files should be the LAST SEGMENT(.zip) and these files should be added in correct order (e.g.: .z01, .z02... .z99, .zip)

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all provided files

Exceptions
IOException:
  • if opening a channel for one of the files fails
  • if the first channel doesn't seem to hold the beginning of a split archive
NullPointerException:
if files is null
Since
1.22
forPathsback to summary
public static SeekableByteChannel forPaths(final Path lastSegmentPath, final Iterable<Path> paths) throws IOException

Concatenates the given file paths.

Parameters
lastSegmentPath:Path

the last segment path of split ZIP segments, its extension must be .zip

paths:Iterable<Path>

the file paths to concatenate except for the last segment, note these files should be added in correct order (e.g.: .z01, .z02... .z99)

Returns:SeekableByteChannel

SeekableByteChannel that concatenates all provided files

Exceptions
IOException:
if the first channel doesn't seem to hold the beginning of a split archive
NullPointerException:
if files or lastSegmentPath is null
Since
1.22
org.apache.commons.compress.archivers.zip back to summary

private final Class ZipSplitReadOnlySeekableByteChannel.ZipSplitSegmentComparator

extends Object
implements Comparator<Path>, Serializable
Class Inheritance
  • java.lang.Object
  • org.apache.commons.compress.archivers.zip.ZipSplitReadOnlySeekableByteChannel.ZipSplitSegmentComparator
All Implemented Interfaces
java.io.Serializable, java.util.Comparator

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(final Path
the first object to be compared.
file1
,
final Path
the second object to be compared.
file2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

ZipSplitSegmentComparatorback to summary
private ZipSplitSegmentComparator()

Method Detail

compareback to summary
public int compare(final Path file1, final Path file2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
file1:Path

the first object to be compared.

file2:Path

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override