Class ZipSplitReadOnlySeekableByteChannel

java.lang.Object
org.apache.commons.compress.utils.MultiReadOnlySeekableByteChannel
org.apache.commons.compress.archivers.zip.ZipSplitReadOnlySeekableByteChannel
All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, ReadableByteChannel, SeekableByteChannel, WritableByteChannel

public class ZipSplitReadOnlySeekableByteChannel extends 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
  • Field Details

    • EMPTY_PATH_ARRAY

      private static final Path[] EMPTY_PATH_ARRAY
    • ZIP_SPLIT_SIGNATURE_LENGTH

      private static final int ZIP_SPLIT_SIGNATURE_LENGTH
      See Also:
    • zipSplitSignatureByteBuffer

      private final ByteBuffer zipSplitSignatureByteBuffer
  • Constructor Details

    • ZipSplitReadOnlySeekableByteChannel

      public ZipSplitReadOnlySeekableByteChannel(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 - the channels to concatenate
      Throws:
      NullPointerException - if channels is null
      IOException - if the first channel doesn't seem to hold the beginning of a split archive
  • Method Details

    • buildFromLastSplitSegment

      public static SeekableByteChannel buildFromLastSplitSegment(File lastSegmentFile) throws IOException
      Concatenates ZIP split files from the last segment(the extension SHOULD be .zip)
      Parameters:
      lastSegmentFile - the last segment of ZIP split files, note that the extension SHOULD be .zip
      Returns:
      SeekableByteChannel that concatenates all ZIP split files
      Throws:
      IllegalArgumentException - if the lastSegmentFile's extension is NOT .zip
      IOException - if the first channel doesn't seem to hold the beginning of a split archive
    • buildFromLastSplitSegment

      public static SeekableByteChannel buildFromLastSplitSegment(Path lastSegmentPath) throws IOException
      Concatenates ZIP split files from the last segment (the extension MUST be .zip)
      Parameters:
      lastSegmentPath - the last segment of ZIP split files, note that the extension MUST be .zip
      Returns:
      SeekableByteChannel that concatenates all ZIP split files
      Throws:
      IllegalArgumentException - if the lastSegmentPath's extension is NOT .zip
      IOException - if the first channel doesn't seem to hold the beginning of a split archive
      Since:
      1.22
    • forFiles

      public static SeekableByteChannel forFiles(File... files) throws IOException
      Concatenates the given files.
      Parameters:
      files - 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 that concatenates all provided files
      Throws:
      NullPointerException - if files is null
      IOException - if opening a channel for one of the files fails
      IOException - if the first channel doesn't seem to hold the beginning of a split archive
    • forFiles

      public static SeekableByteChannel forFiles(File lastSegmentFile, Iterable<File> files) throws IOException
      Concatenates the given files.
      Parameters:
      lastSegmentFile - the last segment of split ZIP segments, its extension should be .zip
      files - 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 that concatenates all provided files
      Throws:
      IOException - if the first channel doesn't seem to hold the beginning of a split archive
      NullPointerException - if files or lastSegmentFile is null
    • forOrderedSeekableByteChannels

      public static SeekableByteChannel forOrderedSeekableByteChannels(SeekableByteChannel... channels) throws IOException
      Concatenates the given channels.
      Parameters:
      channels - 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 that concatenates all provided channels
      Throws:
      NullPointerException - if channels is null
      IOException - if reading channels fails
    • forOrderedSeekableByteChannels

      public static SeekableByteChannel forOrderedSeekableByteChannels(SeekableByteChannel lastSegmentChannel, Iterable<SeekableByteChannel> channels) throws IOException
      Concatenates the given channels.
      Parameters:
      lastSegmentChannel - channel of the last segment of split ZIP segments, its extension should be .zip
      channels - 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 that concatenates all provided channels
      Throws:
      NullPointerException - if lastSegmentChannel or channels is null
      IOException - if the first channel doesn't seem to hold the beginning of a split archive
    • forPaths

      public static SeekableByteChannel forPaths(Path... paths) throws IOException
      Concatenates the given file paths.
      Parameters:
      paths - 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 that concatenates all provided files
      Throws:
      NullPointerException - if files is null
      IOException - if opening a channel for one of the files fails
      IOException - if the first channel doesn't seem to hold the beginning of a split archive
      Since:
      1.22
    • forPaths

      public static SeekableByteChannel forPaths(Path lastSegmentPath, Iterable<Path> paths) throws IOException
      Concatenates the given file paths.
      Parameters:
      lastSegmentPath - the last segment path of split ZIP segments, its extension must be .zip
      paths - 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 that concatenates all provided files
      Throws:
      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
    • assertSplitSignature

      private void assertSplitSignature(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 - channels to be validated
      Throws:
      IOException