public class TransportCursor extends Object implements ByteCursor
TransportCursor
object represents a cursor that
can read and buffer data from an underlying transport. If the
number of bytes read from the cursor is more than required for
the HTTP request then those bytes can be pushed back in to the
cursor using the reset
method. This will only allow
the last read to be reset within the cursor safely.Transport
Constructor and Description |
---|
TransportCursor(Transport transport)
Constructor for the
TransportCursor object. |
TransportCursor(Transport transport,
int size)
Constructor for the
TransportCursor object. |
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 size)
Moves the cursor backward within the stream.
|
public TransportCursor(Transport transport)
TransportCursor
object. This
requires a transport to read the bytes from. By default this
will create a buffer of of the specified size to read the
input in to which enabled bytes to be buffered internally.transport
- this is the underlying transport to usepublic TransportCursor(Transport transport, int size)
TransportCursor
object. This
requires a transport to read the bytes from. By default this
will create a buffer of of the specified size to read the
input in to which enabled bytes to be buffered internally.transport
- this is the underlying transport to usesize
- this is the size of the internal buffer to usepublic boolean isOpen() throws IOException
isOpen
in interface ByteCursor
IOException
public boolean isReady() throws IOException
isReady
in interface ByteCursor
IOException
public int ready() throws IOException
ready
in interface ByteCursor
IOException
public int read(byte[] data) throws IOException
read
in interface ByteCursor
data
- this is the array to read the bytes in toIOException
public int read(byte[] data, int off, int len) throws IOException
read
in interface ByteCursor
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
public 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.push
in interface ByteCursor
data
- this is the data to be pushed on to the cursorIOException
public 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.push
in interface ByteCursor
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
public int reset(int size) throws IOException
reset
in interface ByteCursor
size
- this is the number of bytes to reset backIOException
Copyright © 2018. All rights reserved.