public abstract class AbstractPagedInputView extends Object implements DataInputView
Modifier and Type | Field and Description |
---|---|
protected int |
headerLength |
Modifier | Constructor and Description |
---|---|
protected |
AbstractPagedInputView(int headerLength)
Creates a new view that is initially not bound to a memory segment.
|
protected |
AbstractPagedInputView(MemorySegment initialSegment,
int initialLimit,
int headerLength)
Creates a new view that starts with the given segment.
|
Modifier and Type | Method and Description |
---|---|
void |
advance()
Advances the view to the next memory segment.
|
protected void |
clear()
Clears the internal state of the view.
|
protected void |
doAdvance() |
int |
getCurrentPositionInSegment()
Gets the position from which the next byte will be read.
|
MemorySegment |
getCurrentSegment()
Gets the memory segment that will be used to read the next bytes from.
|
int |
getCurrentSegmentLimit()
Gets the current limit in the memory segment.
|
int |
getHeaderLength() |
protected abstract int |
getLimitForSegment(MemorySegment segment)
Gets the limit for reading bytes from the given memory segment.
|
protected abstract MemorySegment |
nextSegment(MemorySegment current)
The method by which concrete subclasses realize page crossing.
|
int |
read(byte[] b)
Tries to fill the given byte array
b . |
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of memory and stores it into b starting at offset
off . |
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
String |
readLine() |
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
protected void |
seekInput(MemorySegment segment,
int positionInSegment,
int limitInSegment)
Sets the internal state of the view such that the next bytes will be read from the given
memory segment, starting at the given position.
|
int |
skipBytes(int n) |
void |
skipBytesToRead(int numBytes)
Skips
numBytes bytes of memory. |
protected AbstractPagedInputView(MemorySegment initialSegment, int initialLimit, int headerLength)
initialSegment
- The memory segment to start reading from.initialLimit
- The position one after the last valid byte in the initial segment.headerLength
- The number of bytes to skip at the beginning of each segment for the
header. This length must be the same for all memory segments.protected AbstractPagedInputView(int headerLength)
WARNING: The view is not readable until the first call to either advance()
, or to
seekInput(MemorySegment, int, int)
.
headerLength
- The number of bytes to skip at the beginning of each segment for the
header.public MemorySegment getCurrentSegment()
nextSegment(MemorySegment)
method.public int getCurrentPositionInSegment()
getCurrentSegmentLimit()
public int getCurrentSegmentLimit()
getCurrentPositionInSegment()
protected abstract MemorySegment nextSegment(MemorySegment current) throws EOFException, IOException
EOFException
.current
- The current page that was read to its limit. May be null
, if this
method is invoked for the first time.null
. If the
input is exhausted, an EOFException
must be thrown instead.EOFException
- Thrown, if no further segment is available.IOException
- Thrown, if the method cannot provide the next page due to an I/O related
problem.protected abstract int getLimitForSegment(MemorySegment segment)
segment
- The segment to determine the limit for.public void advance() throws IOException
nextSegment(MemorySegment)
and getLimitForSegment(MemorySegment)
to get the next segment and set its limit.IOException
- Thrown, if the next segment could not be obtained.nextSegment(MemorySegment)
,
getLimitForSegment(MemorySegment)
protected void doAdvance() throws IOException
IOException
public int getHeaderLength()
protected void seekInput(MemorySegment segment, int positionInSegment, int limitInSegment)
segment
- The segment to read the next bytes from.positionInSegment
- The position in the segment to start reading from.limitInSegment
- The limit in the segment. When reached, the view will attempt to switch
to the next segment.protected void clear()
advance()
or seekInput(MemorySegment, int, int)
method have been
invoked.public int read(byte[] b) throws IOException
DataInputView
b
. Returns the actually number of read bytes or -1
if there is no more data.read
in interface DataInputView
b
- byte array to store the data toIOException
public int read(byte[] b, int off, int len) throws IOException
DataInputView
len
bytes of memory and stores it into b
starting at offset
off
.
If len
is zero, then no bytes are read and 0
is returned;
otherwise, there is an attempt to read at least one byte. If there is no more data left, the
value -1
is returned; otherwise, at least one byte is read and stored into
b
.
read
in interface DataInputView
b
- byte array to store the data tooff
- offset into byte arraylen
- byte length to readIOException
public void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
public String readLine() throws IOException
readLine
in interface DataInput
IOException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
IOException
public void skipBytesToRead(int numBytes) throws IOException
DataInputView
numBytes
bytes of memory. In contrast to the DataInput.skipBytes(int)
method,
this method always skips the desired number of bytes or throws an EOFException
.skipBytesToRead
in interface DataInputView
numBytes
- The number of bytes to skip.IOException
- Thrown, if any I/O related problem occurred such that the input could not
be advanced to the desired position.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.