Package org.apache.cassandra.hints
Class ChecksummedDataInput
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus
-
- org.apache.cassandra.io.util.RebufferingInputStream
-
- org.apache.cassandra.hints.ChecksummedDataInput
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataInput
,java.lang.AutoCloseable
,DataInputPlus
- Direct Known Subclasses:
CompressedChecksummedDataInput
,EncryptedChecksummedDataInput
public class ChecksummedDataInput extends RebufferingInputStream
ARandomAccessReader
wrapper that calculates the CRC in place. Useful forHintsReader
, 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 thatMutation.MutationSerializer
doesn't blow up the heap when deserializing a corrupted sequence by reading a huge corrupted length of bytes viaByteBufferUtil.readWithLength(java.io.DataInput)
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.cassandra.io.util.DataInputPlus
DataInputPlus.DataInputStreamPlus
-
-
Field Summary
Fields Modifier and Type Field Description protected long
bufferOffset
protected ChannelProxy
channel
-
Fields inherited from class org.apache.cassandra.io.util.RebufferingInputStream
buffer
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
Methods inherited from class org.apache.cassandra.io.util.RebufferingInputStream
read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readPrimitiveSlowly, readShort, readUnsignedByte, readUnsignedShort, readUnsignedVInt, readUnsignedVInt32, readUTF, readVInt, readVInt32, skipBytes
-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.io.util.DataInputPlus
skipBytesFully
-
-
-
-
Field Detail
-
bufferOffset
protected long bufferOffset
-
channel
protected final ChannelProxy channel
-
-
Method Detail
-
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 java.io.IOException
- Throws:
java.io.IOException
-
bytesPastLimit
public long bytesPastLimit()
-
checkCrc
public boolean checkCrc() throws java.io.IOException
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Overrides:
readFully
in classRebufferingInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classRebufferingInputStream
- Throws:
java.io.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 classRebufferingInputStream
-
readBuffer
protected void readBuffer()
-
tryUncacheRead
public void tryUncacheRead()
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
-
getPath
protected java.lang.String getPath()
-
getChannel
public ChannelProxy getChannel()
-
-