Class ChecksummedDataInput

All Implemented Interfaces:
Closeable, DataInput, AutoCloseable, DataInputPlus
Direct Known Subclasses:
CompressedChecksummedDataInput, EncryptedChecksummedDataInput

public class ChecksummedDataInput extends RebufferingInputStream
A RandomAccessReader wrapper that calculates the CRC in place. Useful for HintsReader, for example, where we must verify the CRC, yet don't want to allocate an extra byte array just that purpose. The CRC can be embedded in the input stream and checked via checkCrc(). In addition to calculating the CRC, it allows to enforce a maximum known size. This is needed so that Mutation.MutationSerializer doesn't blow up the heap when deserializing a corrupted sequence by reading a huge corrupted length of bytes via ByteBufferUtil.readWithLength(java.io.DataInput).
  • Field Details

    • bufferOffset

      protected long bufferOffset
    • channel

      protected final ChannelProxy channel
  • Method Details

    • open

      public static ChecksummedDataInput open(File file)
    • isEOF

      public boolean isEOF()
    • getSeekPosition

      public InputPosition getSeekPosition()
      Return a seekable representation of the current position. For compressed files this is chunk position in file and offset within chunk.
    • seek

      public void seek(InputPosition pos)
    • resetCrc

      public void resetCrc()
    • limit

      public void limit(long newLimit)
    • getPosition

      protected long getPosition()
      Returns the exact position in the uncompressed view of the file.
    • getSourcePosition

      protected long getSourcePosition()
      Returns the position in the source file, which is different for getPosition() for compressed/encrypted files and may be imprecise.
    • resetLimit

      public void resetLimit()
    • checkLimit

      public void checkLimit(int length) throws IOException
      Throws:
      IOException
    • bytesPastLimit

      public long bytesPastLimit()
    • checkCrc

      public boolean checkCrc() throws IOException
      Throws:
      IOException
    • readFully

      public void readFully(byte[] b) throws IOException
      Specified by:
      readFully in interface DataInput
      Overrides:
      readFully in class RebufferingInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class RebufferingInputStream
      Throws:
      IOException
    • reBuffer

      protected void reBuffer()
      Description copied from class: RebufferingInputStream
      Implementations must implement this method to refill the buffer. They can expect the buffer to be empty when this method is invoked.
      Specified by:
      reBuffer in class RebufferingInputStream
    • readBuffer

      protected void readBuffer()
    • tryUncacheRead

      public void tryUncacheRead()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
    • getPath

      protected String getPath()
    • getChannel

      public ChannelProxy getChannel()