Class DeferredSeekablePushbackInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable, SeekableDecorator, org.apache.hadoop.fs.Seekable

    public class DeferredSeekablePushbackInputStream
    extends PushbackInputStream
    implements SeekableDecorator
    A wrapper for hadoop input streams created from codecs in ReadMode.BY_BLOCK: Defers reading by one byte such that position changes are advertised on the byte BEFORE the block boundary rather than on the byte AFTER it.
    • Field Detail

      • seekable

        protected org.apache.hadoop.fs.Seekable seekable
      • safeRead

        protected boolean safeRead
        Unsafe reads modify the byte after the reported number of read bytes in the read buffer. Example: If buf := [a, b, c, d] and "read(buf)" returns 3, then buf[3] may no longer hold a 'd'. As this may cause data corruption, safe read mode uses an intermediate buffer with additional copying to prevent changing data outside of the reported range.
      • fallbackBuffer

        protected byte[] fallbackBuffer
    • Constructor Detail

      • DeferredSeekablePushbackInputStream

        public DeferredSeekablePushbackInputStream​(InputStream in)
      • DeferredSeekablePushbackInputStream

        public DeferredSeekablePushbackInputStream​(InputStream in,
                                                   org.apache.hadoop.fs.Seekable seekable)
    • Method Detail

      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws IOException
        This method essentially delays reads by one byte. Whereas hadoop's codec protocol reads one byte past block boundaries, this method buffers one byte on every read such that once the underlying stream reads accross the block boundary -- indicated by a position change -- only the byte before the block boundary is returned.
        Overrides:
        read in class PushbackInputStream
        Returns:
        Throws:
        IOException
      • readInternal

        protected int readInternal​(byte[] b,
                                   int off,
                                   int len)
                            throws IOException
        This method is assumed to be invoked with len >= 2
        Throws:
        IOException
      • afterSeek

        protected void afterSeek()