Class ZipSplitReadOnlySeekableByteChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.SeekableByteChannel, java.nio.channels.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 Detail

      • ZIP_SPLIT_SIGNATURE_LENGTH

        private static final int ZIP_SPLIT_SIGNATURE_LENGTH
        See Also:
        Constant Field Values
      • zipSplitSignatureByteBuffer

        private final java.nio.ByteBuffer zipSplitSignatureByteBuffer
    • Constructor Detail

      • ZipSplitReadOnlySeekableByteChannel

        public ZipSplitReadOnlySeekableByteChannel​(java.util.List<java.nio.channels.SeekableByteChannel> channels)
                                            throws java.io.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:
        java.lang.NullPointerException - if channels is null
        java.io.IOException - if the first channel doesn't seem to hold the beginning of a split archive
    • Method Detail

      • assertSplitSignature

        private void assertSplitSignature​(java.util.List<java.nio.channels.SeekableByteChannel> channels)
                                   throws java.io.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:
        java.io.IOException
      • forOrderedSeekableByteChannels

        public static java.nio.channels.SeekableByteChannel forOrderedSeekableByteChannels​(java.nio.channels.SeekableByteChannel... channels)
                                                                                    throws java.io.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 theses channels should be added in correct order (e.g. .z01, .z02... .z99, .zip)
        Returns:
        SeekableByteChannel that concatenates all provided channels
        Throws:
        java.lang.NullPointerException - if channels is null
        java.io.IOException - if reading channels fails
      • forOrderedSeekableByteChannels

        public static java.nio.channels.SeekableByteChannel forOrderedSeekableByteChannels​(java.nio.channels.SeekableByteChannel lastSegmentChannel,
                                                                                           java.lang.Iterable<java.nio.channels.SeekableByteChannel> channels)
                                                                                    throws java.io.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 theses channels should be added in correct order (e.g. .z01, .z02... .z99)
        Returns:
        SeekableByteChannel that concatenates all provided channels
        Throws:
        java.lang.NullPointerException - if lastSegmentChannel or channels is null
        java.io.IOException - if the first channel doesn't seem to hold the beginning of a split archive
      • buildFromLastSplitSegment

        public static java.nio.channels.SeekableByteChannel buildFromLastSplitSegment​(java.io.File lastSegmentFile)
                                                                               throws java.io.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:
        java.lang.IllegalArgumentException - if the lastSegmentFile's extension is NOT .zip
        java.io.IOException - if the first channel doesn't seem to hold the beginning of a split archive
      • forFiles

        public static java.nio.channels.SeekableByteChannel forFiles​(java.io.File... files)
                                                              throws java.io.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 theses files should be added in correct order (e.g. .z01, .z02... .z99, .zip)
        Returns:
        SeekableByteChannel that concatenates all provided files
        Throws:
        java.lang.NullPointerException - if files is null
        java.io.IOException - if opening a channel for one of the files fails
        java.io.IOException - if the first channel doesn't seem to hold the beginning of a split archive
      • forFiles

        public static java.nio.channels.SeekableByteChannel forFiles​(java.io.File lastSegmentFile,
                                                                     java.lang.Iterable<java.io.File> files)
                                                              throws java.io.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 theses files should be added in correct order (e.g. .z01, .z02... .z99)
        Returns:
        SeekableByteChannel that concatenates all provided files
        Throws:
        java.io.IOException - if the first channel doesn't seem to hold the beginning of a split archive
        java.lang.NullPointerException - if files or lastSegmentFile is null