Package org.apache.cassandra.io.util
Class RandomAccessReader
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus
-
- org.apache.cassandra.io.util.RebufferingInputStream
-
- org.apache.cassandra.io.util.RandomAccessReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataInput
,java.lang.AutoCloseable
,DataInputPlus
,FileDataInput
,RewindableDataInput
- Direct Known Subclasses:
RandomAccessReaderAdapter
@NotThreadSafe public class RandomAccessReader extends RebufferingInputStream implements FileDataInput
-
-
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 Rebufferer.BufferHolder
bufferHolder
static int
DEFAULT_BUFFER_SIZE
-
Fields inherited from class org.apache.cassandra.io.util.RebufferingInputStream
buffer
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RandomAccessReader(Rebufferer rebufferer)
Only created through Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
long
bytesPastMark()
long
bytesPastMark(DataPosition mark)
long
bytesRemaining()
void
close()
protected long
current()
ChannelProxy
getChannel()
double
getCrcCheckChance()
long
getFilePointer()
java.lang.String
getPath()
long
getPosition()
boolean
isEOF()
long
length()
DataPosition
mark()
boolean
markSupported()
static RandomAccessReader
open(File file)
Open a RandomAccessReader (not compressed, not mmapped, no read throttling) that will own its channel.java.lang.String
readLine()
Reads a line of text form the current position in this file.void
reBuffer()
Read data from file starting from current currentOffset to populate buffer.void
reset()
void
reset(DataPosition mark)
void
seek(long newPosition)
int
skipBytes(int n)
Always skips the requested number of bytes, unless EOF is reachedjava.lang.String
toString()
-
Methods inherited from class org.apache.cassandra.io.util.RebufferingInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readFully, readInt, readLong, readPrimitiveSlowly, readShort, readUnsignedByte, readUnsignedShort, readUnsignedVInt, readUnsignedVInt32, readUTF, readVInt, readVInt32
-
Methods inherited from class java.io.InputStream
mark, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skip, transferTo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF
-
Methods inherited from interface org.apache.cassandra.io.util.DataInputPlus
readUnsignedVInt, readUnsignedVInt32, readVInt, readVInt32, skipBytesFully
-
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
bufferHolder
protected Rebufferer.BufferHolder bufferHolder
-
-
Constructor Detail
-
RandomAccessReader
protected RandomAccessReader(Rebufferer rebufferer)
Only created through Builder- Parameters:
rebufferer
- Rebufferer to use
-
-
Method Detail
-
reBuffer
public void reBuffer()
Read data from file starting from current currentOffset to populate buffer.- Specified by:
reBuffer
in classRebufferingInputStream
-
getFilePointer
public long getFilePointer()
- Specified by:
getFilePointer
in interfaceFileDataInput
-
current
protected long current()
-
getPath
public java.lang.String getPath()
- Specified by:
getPath
in interfaceFileDataInput
-
getChannel
public ChannelProxy getChannel()
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classjava.io.InputStream
-
bytesPastMark
public long bytesPastMark()
-
mark
public DataPosition mark()
- Specified by:
mark
in interfaceRewindableDataInput
-
reset
public void reset(DataPosition mark)
- Specified by:
reset
in interfaceRewindableDataInput
-
bytesPastMark
public long bytesPastMark(DataPosition mark)
- Specified by:
bytesPastMark
in interfaceRewindableDataInput
-
isEOF
public boolean isEOF()
- Specified by:
isEOF
in interfaceFileDataInput
- Returns:
- true if there is no more data to read
-
bytesRemaining
public long bytesRemaining()
- Specified by:
bytesRemaining
in interfaceFileDataInput
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
seek
public void seek(long newPosition)
- Specified by:
seek
in interfaceFileDataInput
-
skipBytes
public int skipBytes(int n) throws java.io.IOException
Description copied from interface:DataInputPlus
Always skips the requested number of bytes, unless EOF is reached- Specified by:
skipBytes
in interfacejava.io.DataInput
- Specified by:
skipBytes
in interfaceDataInputPlus
- Overrides:
skipBytes
in classRebufferingInputStream
- Parameters:
n
- number of bytes to skip- Returns:
- number of bytes skipped
- Throws:
java.io.IOException
-
readLine
public final java.lang.String readLine() throws java.io.IOException
Reads a line of text form the current position in this file. A line is represented by zero or more characters followed by'\n'
,'\r'
,"\r\n"
or the end of file marker. The string does not include the line terminating sequence.Blocks until a line terminating sequence has been read, the end of the file is reached or an exception is thrown.
- Specified by:
readLine
in interfacejava.io.DataInput
- Overrides:
readLine
in classRebufferingInputStream
- Returns:
- the contents of the line or
null
if no characters have been read before the end of the file has been reached. - Throws:
java.io.IOException
- if this file is closed or another I/O error occurs.
-
length
public long length()
-
getPosition
public long getPosition()
-
getCrcCheckChance
public double getCrcCheckChance()
-
open
public static RandomAccessReader open(File file)
Open a RandomAccessReader (not compressed, not mmapped, no read throttling) that will own its channel.- Parameters:
file
- File to open for reading- Returns:
- new RandomAccessReader that owns the channel opened in this method.
-
-