Package org.apache.cassandra.hints
Class ChecksummedDataInput
- java.lang.Object
-
- java.io.InputStream
-
- 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
ARandomAccessReaderwrapper 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.MutationSerializerdoesn'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 longbufferOffsetprotected ChannelProxychannel-
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 longbytesPastLimit()booleancheckCrc()voidcheckLimit(int length)voidclose()ChannelProxygetChannel()protected java.lang.StringgetPath()protected longgetPosition()Returns the exact position in the uncompressed view of the file.InputPositiongetSeekPosition()Return a seekable representation of the current position.protected longgetSourcePosition()Returns the position in the source file, which is different for getPosition() for compressed/encrypted files and may be imprecise.booleanisEOF()voidlimit(long newLimit)static ChecksummedDataInputopen(File file)intread(byte[] b, int off, int len)protected voidreadBuffer()voidreadFully(byte[] b)protected voidreBuffer()Implementations must implement this method to refill the buffer.voidresetCrc()voidresetLimit()voidseek(InputPosition pos)voidtryUncacheRead()-
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, readUTF, readVInt, 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:
readFullyin interfacejava.io.DataInput- Overrides:
readFullyin classRebufferingInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classRebufferingInputStream- Throws:
java.io.IOException
-
reBuffer
protected void reBuffer()
Description copied from class:RebufferingInputStreamImplementations must implement this method to refill the buffer. They can expect the buffer to be empty when this method is invoked.- Specified by:
reBufferin classRebufferingInputStream
-
readBuffer
protected void readBuffer()
-
tryUncacheRead
public void tryUncacheRead()
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream
-
getPath
protected java.lang.String getPath()
-
getChannel
public ChannelProxy getChannel()
-
-