Package org.simpleframework.transport
Class TransportCursor
- java.lang.Object
-
- org.simpleframework.transport.TransportCursor
-
- All Implemented Interfaces:
Cursor
public class TransportCursor extends java.lang.Object implements Cursor
TheTransportCursor
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 thereset
method. This will only allow the last read to be reset within the cursor safely.- Author:
- Niall Gallagher
- See Also:
Transport
-
-
Constructor Summary
Constructors Constructor Description TransportCursor(Transport transport)
Constructor for theTransportCursor
object.TransportCursor(Transport transport, int size)
Constructor for theTransportCursor
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
TransportCursor
public TransportCursor(Transport transport)
Constructor for theTransportCursor
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.- Parameters:
transport
- this is the underlying transport to use
-
TransportCursor
public TransportCursor(Transport transport, int size)
Constructor for theTransportCursor
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.- Parameters:
transport
- this is the underlying transport to usesize
- this is the size of the internal buffer to use
-
-
Method Detail
-
isOpen
public boolean isOpen() throws java.io.IOException
Determines whether the cursor is still open. The cursor is considered open if there are still bytes to read. If there is still bytes buffered and the underlying transport is closed then the cursor is still considered open.
-
isReady
public boolean isReady() throws java.io.IOException
Determines whether the cursor is ready for reading. When the cursor is ready then it guarantees that some amount of bytes can be read from the underlying stream without blocking.
-
ready
public int ready() throws java.io.IOException
Provides the number of bytes that can be read from the stream without blocking. This is typically the number of buffered or available bytes within the stream. When this reaches zero then the cursor may perform a blocking read.
-
read
public int read(byte[] data) throws java.io.IOException
Reads a block of bytes from the underlying stream. This will read up to the requested number of bytes from the underlying stream. If there are no ready bytes on the stream this can return zero, representing the fact that nothing was read.
-
read
public int read(byte[] data, int off, int len) throws java.io.IOException
Reads a block of bytes from the underlying stream. This will read up to the requested number of bytes from the underlying stream. If there are no ready bytes on the stream this can return zero, representing the fact that nothing was read.
-
push
public void push(byte[] data) throws java.io.IOException
Pushes the provided data on to the cursor. Data pushed on to the cursor will be the next data read from the cursor. This complements thereset
method which will reset the cursors position on a stream. Allowing data to be pushed on to the cursor allows more flexibility.
-
push
public void push(byte[] data, int off, int len) throws java.io.IOException
Pushes the provided data on to the cursor. Data pushed on to the cursor will be the next data read from the cursor. This complements thereset
method which will reset the cursors position on a stream. Allowing data to be pushed on to the cursor allows more flexibility.
-
reset
public int reset(int size) throws java.io.IOException
Moves the cursor backward within the stream. This ensures that any bytes read from the last read can be pushed back in to the stream so that they can be read again. This will throw an exception if the reset can not be performed.
-
-