public interface ByteCursor
ByteCursor
object is used to acquire bytes from a
given source. This provides a cursor style reading of bytes from
a stream in that it will allow the reader to move the cursor back
if the amount of bytes read is too much. Allowing the cursor to
move ensures that excess bytes back be placed back in the stream.
This is used when parsing input from a stream as it ensures that on arrival at a terminal token any excess bytes can be placed back in to the stream. This allows data to be read efficiently in large chunks from blocking streams such as sockets.
TransportCursor
Modifier and Type | Method and Description |
---|---|
boolean |
isOpen()
Determines whether the cursor is still open.
|
boolean |
isReady()
Determines whether the cursor is ready for reading.
|
void |
push(byte[] data)
Pushes the provided data on to the cursor.
|
void |
push(byte[] data,
int off,
int len)
Pushes the provided data on to the cursor.
|
int |
read(byte[] data)
Reads a block of bytes from the underlying stream.
|
int |
read(byte[] data,
int off,
int len)
Reads a block of bytes from the underlying stream.
|
int |
ready()
Provides the number of bytes that can be read from the stream
without blocking.
|
int |
reset(int len)
Moves the cursor backward within the stream.
|
boolean isOpen() throws IOException
IOException
boolean isReady() throws IOException
IOException
int ready() throws IOException
IOException
int read(byte[] data) throws IOException
data
- this is the array to read the bytes in toIOException
int read(byte[] data, int off, int len) throws IOException
data
- this is the array to read the bytes in tooff
- this is the offset to begin writing the bytes tolen
- this is the number of bytes that are requestedIOException
void push(byte[] data) throws IOException
reset
method which will reset
the cursors position on a stream. Allowing data to be pushed
on to the cursor allows more flexibility.data
- this is the data to be pushed on to the cursorIOException
void push(byte[] data, int off, int len) throws IOException
reset
method which will reset
the cursors position on a stream. Allowing data to be pushed
on to the cursor allows more flexibility.data
- this is the data to be pushed on to the cursoroff
- this is the offset to begin reading the byteslen
- this is the number of bytes that are to be usedIOException
int reset(int len) throws IOException
len
- this is the number of bytes to reset backIOException
Copyright © 2022. All rights reserved.