Class AbstractSnappyInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    SnappyFramedInputStream, SnappyInputStream

    abstract class AbstractSnappyInputStream
    extends java.io.InputStream
    A common base class for frame based snappy input streams.
    • Field Detail

      • in

        private final java.io.InputStream in
      • frameHeader

        private final byte[] frameHeader
      • verifyChecksums

        private final boolean verifyChecksums
      • input

        private byte[] input
        A single frame read from the underlying InputStream.
      • uncompressed

        private byte[] uncompressed
        The decompressed data from input.
      • closed

        private boolean closed
        Indicates if this instance has been closed.
      • eof

        private boolean eof
        Indicates if we have reached the EOF on in.
      • valid

        private int valid
        The position in input to read to.
      • position

        private int position
        The next position to read from buffer.
      • buffer

        private byte[] buffer
        Buffer is a reference to the real buffer of uncompressed data for the current block: uncompressed if the block is compressed, or input if it is not.
    • Constructor Detail

      • AbstractSnappyInputStream

        public AbstractSnappyInputStream​(java.io.InputStream in,
                                         int maxBlockSize,
                                         int frameHeaderSize,
                                         boolean verifyChecksums,
                                         byte[] expectedHeader)
                                  throws java.io.IOException
        Creates a Snappy input stream to read data from the specified underlying input stream.
        Parameters:
        in - the underlying input stream
        verifyChecksums - if true, checksums in input stream will be verified
        expectedHeader - the expected stream header
        Throws:
        java.io.IOException
    • Method Detail

      • allocateBuffersBasedOnSize

        private void allocateBuffersBasedOnSize​(int size)
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] output,
                        int offset,
                        int length)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • 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.InputStream
        Throws:
        java.io.IOException
      • ensureBuffer

        private boolean ensureBuffer()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • getFrameMetaData

        protected abstract AbstractSnappyInputStream.FrameMetaData getFrameMetaData​(byte[] frameHeader)
                                                                             throws java.io.IOException
        Use the content of the frameHeader to describe what type of frame we have and the action to take.
        Throws:
        java.io.IOException
      • getFrameData

        protected abstract AbstractSnappyInputStream.FrameData getFrameData​(byte[] frameHeader,
                                                                            byte[] content,
                                                                            int length)
        Take the frame header and the content of the frame to describe metadata about the content.
        Parameters:
        frameHeader - The frame header.
        content - The content of the of the frame. Content begins at index 0.
        length - The length of the content.
        Returns:
        Metadata about the content of the frame.
      • readBlockHeader

        private boolean readBlockHeader()
                                 throws java.io.IOException
        Throws:
        java.io.IOException