com.mindbright.nio
public class NonBlockingInput extends java.lang.Object
Modifier | Constructor and Description |
---|---|
|
NonBlockingInput(java.nio.channels.Pipe pipe)
Create a new NonBlockingInput object which reads data from the
given pipe.
|
protected |
NonBlockingInput(Switchboard switchboard,
java.nio.channels.spi.AbstractSelectableChannel channel) |
Modifier and Type | Method and Description |
---|---|
protected void |
clearReadWaiting() |
void |
close()
Close the underlying stream.
|
java.nio.ByteBuffer |
createBuffer(byte[] array)
Create a ByteBuffer wrapped around the provided array
|
java.nio.ByteBuffer |
createBuffer(byte[] array,
int offset)
Create a ByteBuffer wrapped around the provided array
|
java.nio.ByteBuffer |
createBuffer(byte[] array,
int offset,
int length)
Create a ByteBuffer wrapped around the provided array
|
void |
pushback(byte[] data,
int offset,
int length)
Push back data onto the stream so that future reads will get it.
|
void |
read(java.nio.ByteBuffer buf)
Reads data from the stream and places it in the provided
buffer.
|
boolean |
read(java.nio.ByteBuffer buf,
int offset,
int length,
NIOCallback callback,
boolean mayShortcut,
boolean shortDataOk)
Reads data from the stream and places it in the provided
buffer.
|
void |
read(java.nio.ByteBuffer buf,
NIOCallback callback)
Reads data from the stream and places it in the provided
buffer.
|
boolean |
read(java.nio.ByteBuffer buf,
NIOCallback callback,
boolean mayShortcut,
boolean shortDataOk)
Reads data from the stream and places it in the provided
buffer.
|
protected NonBlockingInput(Switchboard switchboard, java.nio.channels.spi.AbstractSelectableChannel channel) throws java.io.IOException
java.io.IOException
public NonBlockingInput(java.nio.channels.Pipe pipe) throws java.io.IOException
pipe
- The pipe the object will read fromjava.io.IOException
public void read(java.nio.ByteBuffer buf) throws java.io.IOException
The method will fill the buffer from the current position to the limit.
buf
- buffer in which to store the read datajava.io.IOException
public void read(java.nio.ByteBuffer buf, NIOCallback callback) throws java.io.IOException
The method will fill the buffer from the current position to the limit.
buf
- buffer in which to store the read datacallback
- class to notify when data has been readjava.io.IOException
public boolean read(java.nio.ByteBuffer buf, NIOCallback callback, boolean mayShortcut, boolean shortDataOk) throws java.io.IOException
The method will try to fill the buffer from the current
position to the limit. But if shortDataOk
is true
then the callback will be called as soon as at least one byte
has been read.
buf
- buffer in which to store the read datacallback
- class to notify when data has been read
(unless data is available immediately)mayShortcut
- If this is true then the function will not
call the callback if data is available
immediately but instead return true.shortDataOk
- If this is ok then the call will return/call
the callback as soon as data is available,
even if the buffer is not full.java.io.IOException
public boolean read(java.nio.ByteBuffer buf, int offset, int length, NIOCallback callback, boolean mayShortcut, boolean shortDataOk) throws java.io.IOException
The method will try to fill the buffer from the current
position to the limit. But if shortDataOk
is true
then the callback will be called as soon as at least one byte
has been read.
buf
- buffer in which to store the read datacallback
- class to notify when data has been read
(unless data is available immediately)mayShortcut
- If this is true then the function will not
call the callback if data is available
immediately but instead return true.shortDataOk
- If this is ok then the call will return/call
the callback as soon as data is available,
even if the buffer is not full.java.io.IOException
protected void clearReadWaiting()
public void pushback(byte[] data, int offset, int length)
data
- array holding data to push backoffset
- offset to start getting data fromlength
- number of bytes to push backpublic void close() throws java.io.IOException
java.io.IOException
public java.nio.ByteBuffer createBuffer(byte[] array)
public java.nio.ByteBuffer createBuffer(byte[] array, int offset)
public java.nio.ByteBuffer createBuffer(byte[] array, int offset, int length)