Class SnappyFramedOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.WritableByteChannel

    public final class SnappyFramedOutputStream
    extends java.io.OutputStream
    implements java.nio.channels.WritableByteChannel
    Implements the x-snappy-framed as an OutputStream and WritableByteChannel.
    Since:
    1.1.0
    • Field Detail

      • MAX_BLOCK_SIZE

        public static final int MAX_BLOCK_SIZE
        The x-snappy-framed specification allows for a chunk size up to 16,777,211 bytes in length. However, it also goes on to state:

        We place an additional restriction that the uncompressed data in a chunk must be no longer than 65536 bytes. This allows consumers to easily use small fixed-size buffers.

        See Also:
        Constant Field Values
      • DEFAULT_BLOCK_SIZE

        public static final int DEFAULT_BLOCK_SIZE
        The default block size to use.
        See Also:
        Constant Field Values
      • DEFAULT_MIN_COMPRESSION_RATIO

        public static final double DEFAULT_MIN_COMPRESSION_RATIO
        The default min compression ratio to use.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SnappyFramedOutputStream

        public SnappyFramedOutputStream​(java.io.OutputStream out,
                                        BufferPool bufferPool)
                                 throws java.io.IOException
        Parameters:
        out - The underlying OutputStream to write to. Must not be null.
        bufferPool - Used to obtain buffer instances. Must not be null.
        Throws:
        java.io.IOException
      • SnappyFramedOutputStream

        public SnappyFramedOutputStream​(java.io.OutputStream out,
                                        int blockSize,
                                        double minCompressionRatio)
                                 throws java.io.IOException
        Creates a new SnappyFramedOutputStream instance.

        Uses DefaultPoolFactory to obtain BufferPool for buffers.

        Parameters:
        out - The underlying OutputStream to write to. Must not be null.
        blockSize - The block size (of raw data) to compress before writing frames to out. Must be in (0, 65536].
        minCompressionRatio - Defines the minimum compression ratio ( compressedLength / rawLength) that must be achieved to write the compressed data. This must be in (0, 1.0].
        Throws:
        java.io.IOException
      • SnappyFramedOutputStream

        public SnappyFramedOutputStream​(java.io.OutputStream out,
                                        int blockSize,
                                        double minCompressionRatio,
                                        BufferPool bufferPool)
                                 throws java.io.IOException
        Creates a new SnappyFramedOutputStream instance.
        Parameters:
        out - The underlying OutputStream to write to. Must not be null.
        blockSize - The block size (of raw data) to compress before writing frames to out. Must be in (0, 65536].
        minCompressionRatio - Defines the minimum compression ratio ( compressedLength / rawLength) that must be achieved to write the compressed data. This must be in (0, 1.0].
        bufferPool - Used to obtain buffer instances. Must not be null.
        Throws:
        java.io.IOException
      • SnappyFramedOutputStream

        public SnappyFramedOutputStream​(java.nio.channels.WritableByteChannel out,
                                        int blockSize,
                                        double minCompressionRatio)
                                 throws java.io.IOException
        Creates a new SnappyFramedOutputStream instance.
        Parameters:
        out - The underlying WritableByteChannel to write to. Must not be null.
        blockSize - The block size (of raw data) to compress before writing frames to out. Must be in (0, 65536].
        minCompressionRatio - Defines the minimum compression ratio ( compressedLength / rawLength) that must be achieved to write the compressed data. This must be in (0, 1.0].
        Throws:
        java.io.IOException
        Since:
        1.1.1
      • SnappyFramedOutputStream

        public SnappyFramedOutputStream​(java.nio.channels.WritableByteChannel out,
                                        int blockSize,
                                        double minCompressionRatio,
                                        BufferPool bufferPool)
                                 throws java.io.IOException
        Creates a new SnappyFramedOutputStream instance.
        Parameters:
        out - The underlying WritableByteChannel to write to. Must not be null.
        blockSize - The block size (of raw data) to compress before writing frames to out. Must be in (0, 65536].
        minCompressionRatio - Defines the minimum compression ratio ( compressedLength / rawLength) that must be achieved to write the compressed data. This must be in (0, 1.0].
        bufferPool - Used to obtain buffer instances. Must not be null.
        Throws:
        java.io.IOException
        Since:
        1.1.1
    • Method Detail

      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • write

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

        public void write​(byte[] input,
                          int offset,
                          int length)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer src)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Throws:
        java.io.IOException
      • transferFrom

        public long transferFrom​(java.io.InputStream is)
                          throws java.io.IOException
        Transfers all the content from is to this OutputStream. This potentially limits the amount of buffering required to compress content.
        Parameters:
        is - The source of data to compress.
        Returns:
        The number of bytes read from is.
        Throws:
        java.io.IOException
        Since:
        1.1.1
      • transferFrom

        public long transferFrom​(java.nio.channels.ReadableByteChannel rbc)
                          throws java.io.IOException
        Transfers all the content from rbc to this WritableByteChannel. This potentially limits the amount of buffering required to compress content.
        Parameters:
        rbc - The source of data to compress.
        Returns:
        The number of bytes read from rbc.
        Throws:
        java.io.IOException
        Since:
        1.1.1
      • flush

        public final 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
      • close

        public final void close()
                         throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException