public class ChecksummedDataInput extends RebufferingInputStream
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)
.DataInputPlus.DataInputStreamPlus
Modifier and Type | Field and Description |
---|---|
protected long |
bufferOffset |
protected ChannelProxy |
channel |
buffer
Modifier and Type | Method and Description |
---|---|
long |
bytesPastLimit() |
boolean |
checkCrc() |
void |
checkLimit(int length) |
void |
close() |
ChannelProxy |
getChannel() |
protected java.lang.String |
getPath() |
protected long |
getPosition()
Returns the exact position in the uncompressed view of the file.
|
InputPosition |
getSeekPosition()
Return a seekable representation of the current position.
|
protected long |
getSourcePosition()
Returns the position in the source file, which is different for getPosition() for compressed/encrypted files
and may be imprecise.
|
boolean |
isEOF() |
void |
limit(long newLimit) |
static ChecksummedDataInput |
open(File file) |
int |
read(byte[] b,
int off,
int len) |
protected void |
readBuffer() |
void |
readFully(byte[] b) |
protected void |
reBuffer()
Implementations must implement this method to refill the buffer.
|
void |
resetCrc() |
void |
resetLimit() |
void |
seek(InputPosition pos) |
void |
tryUncacheRead() |
read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readPrimitiveSlowly, readShort, readUnsignedByte, readUnsignedShort, readUnsignedVInt, readUTF, readVInt, skipBytes
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
skipBytesFully
protected long bufferOffset
protected final ChannelProxy channel
public static ChecksummedDataInput open(File file)
public boolean isEOF()
public InputPosition getSeekPosition()
public void seek(InputPosition pos)
public void resetCrc()
public void limit(long newLimit)
protected long getPosition()
protected long getSourcePosition()
public void resetLimit()
public void checkLimit(int length) throws java.io.IOException
java.io.IOException
public long bytesPastLimit()
public boolean checkCrc() throws java.io.IOException
java.io.IOException
public void readFully(byte[] b) throws java.io.IOException
readFully
in interface java.io.DataInput
readFully
in class RebufferingInputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class RebufferingInputStream
java.io.IOException
protected void reBuffer()
RebufferingInputStream
reBuffer
in class RebufferingInputStream
protected void readBuffer()
public void tryUncacheRead()
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
protected java.lang.String getPath()
public ChannelProxy getChannel()
Copyright © 2009-2022 The Apache Software Foundation