Class StreamCompressor

    • Field Detail

      • def

        private final java.util.zip.Deflater def
      • crc

        private final java.util.zip.CRC32 crc
      • writtenToOutputStreamForLastEntry

        private long writtenToOutputStreamForLastEntry
      • sourcePayloadLength

        private long sourcePayloadLength
      • totalWrittenToOutputStream

        private long totalWrittenToOutputStream
      • outputBuffer

        private final byte[] outputBuffer
      • readerBuf

        private final byte[] readerBuf
    • Constructor Detail

      • StreamCompressor

        StreamCompressor​(java.util.zip.Deflater deflater)
    • Method Detail

      • create

        static StreamCompressor create​(java.io.OutputStream os,
                                       java.util.zip.Deflater deflater)
        Create a stream compressor with the given compression level.
        Parameters:
        os - The stream to receive output
        deflater - The deflater to use
        Returns:
        A stream compressor
      • create

        static StreamCompressor create​(java.io.OutputStream os)
        Create a stream compressor with the default compression level.
        Parameters:
        os - The stream to receive output
        Returns:
        A stream compressor
      • create

        static StreamCompressor create​(java.io.DataOutput os,
                                       java.util.zip.Deflater deflater)
        Create a stream compressor with the given compression level.
        Parameters:
        os - The DataOutput to receive output
        deflater - The deflater to use for the compressor
        Returns:
        A stream compressor
      • create

        static StreamCompressor create​(java.nio.channels.SeekableByteChannel os,
                                       java.util.zip.Deflater deflater)
        Create a stream compressor with the given compression level.
        Parameters:
        os - The SeekableByteChannel to receive output
        deflater - The deflater to use for the compressor
        Returns:
        A stream compressor
        Since:
        1.13
      • create

        public static StreamCompressor create​(int compressionLevel,
                                              ScatterGatherBackingStore bs)
        Create a stream compressor with the given compression level.
        Parameters:
        compressionLevel - The Deflater compression level
        bs - The ScatterGatherBackingStore to receive output
        Returns:
        A stream compressor
      • create

        public static StreamCompressor create​(ScatterGatherBackingStore bs)
        Create a stream compressor with the default compression level.
        Parameters:
        bs - The ScatterGatherBackingStore to receive output
        Returns:
        A stream compressor
      • getCrc32

        public long getCrc32()
        The crc32 of the last deflated file
        Returns:
        the crc32
      • getBytesRead

        public long getBytesRead()
        Return the number of bytes read from the source stream
        Returns:
        The number of bytes read, never negative
      • getBytesWrittenForLastEntry

        public long getBytesWrittenForLastEntry()
        The number of bytes written to the output for the last entry
        Returns:
        The number of bytes, never negative
      • getTotalBytesWritten

        public long getTotalBytesWritten()
        The total number of bytes written to the output for all files
        Returns:
        The number of bytes, never negative
      • deflate

        public void deflate​(java.io.InputStream source,
                            int method)
                     throws java.io.IOException
        Deflate the given source using the supplied compression method
        Parameters:
        source - The source to compress
        method - The #ZipArchiveEntry compression method
        Throws:
        java.io.IOException - When failures happen
      • write

        long write​(byte[] b,
                   int offset,
                   int length,
                   int method)
            throws java.io.IOException
        Writes bytes to ZIP entry.
        Parameters:
        b - the byte array to write
        offset - the start position to write from
        length - the number of bytes to write
        method - the comrpession method to use
        Returns:
        the number of bytes written to the stream this time
        Throws:
        java.io.IOException - on error
      • reset

        void reset()
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • flushDeflater

        void flushDeflater()
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeDeflated

        private void writeDeflated​(byte[] b,
                                   int offset,
                                   int length)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • deflateUntilInputIsNeeded

        private void deflateUntilInputIsNeeded()
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • deflate

        void deflate()
              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCounted

        public void writeCounted​(byte[] data)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCounted

        public void writeCounted​(byte[] data,
                                 int offset,
                                 int length)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeOut

        protected abstract void writeOut​(byte[] data,
                                         int offset,
                                         int length)
                                  throws java.io.IOException
        Throws:
        java.io.IOException