Class OptimizedGZIPOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class OptimizedGZIPOutputStream
    extends java.io.OutputStream
    Optimized variant of GZIPOutputStream that reuses underlying Deflater instance}.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.zip.CRC32 _crc  
      protected java.util.zip.Deflater _deflater  
      protected java.util.zip.DeflaterOutputStream _deflaterOut  
      protected byte[] _eightByteBuffer  
      protected GZIPRecycler _gzipRecycler  
      protected java.io.OutputStream _rawOut
      Underlying output stream that header, compressed content and footer go to
      (package private) static byte[] DEFAULT_HEADER
      For now, static header seems fine, since JDK default gzip writer does it too:
      private static int GZIP_MAGIC
      GZIP header magic number; written out LSB like most everything else (i.e.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void _putInt​(byte[] buf, int offset, int value)
      Stupid GZIP, writes stuff in wrong order (not network, but x86)
      private void _writeTrailer​(java.io.OutputStream out)  
      void close()  
      void flush()  
      void write​(byte[] buf)  
      void write​(byte[] buf, int off, int len)  
      void write​(int c)  
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • GZIP_MAGIC

        private static final int GZIP_MAGIC
        GZIP header magic number; written out LSB like most everything else (i.e. as 0x1f 0x8b)
        See Also:
        Constant Field Values
      • DEFAULT_HEADER

        static final byte[] DEFAULT_HEADER
        For now, static header seems fine, since JDK default gzip writer does it too:
      • _deflater

        protected java.util.zip.Deflater _deflater
      • _eightByteBuffer

        protected final byte[] _eightByteBuffer
      • _rawOut

        protected java.io.OutputStream _rawOut
        Underlying output stream that header, compressed content and footer go to
      • _deflaterOut

        protected java.util.zip.DeflaterOutputStream _deflaterOut
      • _crc

        protected java.util.zip.CRC32 _crc
    • Constructor Detail

      • OptimizedGZIPOutputStream

        public OptimizedGZIPOutputStream​(java.io.OutputStream out)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • close

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

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public final void write​(byte[] buf)
                         throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public final void write​(int c)
                         throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] buf,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • _writeTrailer

        private void _writeTrailer​(java.io.OutputStream out)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • _putInt

        private static final void _putInt​(byte[] buf,
                                          int offset,
                                          int value)
        Stupid GZIP, writes stuff in wrong order (not network, but x86)