|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--org.szegedi.nbpipe.NonblockingPipe
NonblockingPipe is a device for bridging between one-connection-per-thread code and the multiple-connections-per-thread (nio) code. The legacy code must be shielded from both the complexity of non-blocking I/O and from getting blocked on I/O. This is where a NonblockingPipe comes in. This pipe uses a ByteBufferPool to satisfy its memory needs, and does not work with an ordinary cyclic buffer that blocks write operations when full. This way, it is ideal for presenting InputStream and OutputStream interfaces for legacy code, while retaining full non-blocking I/O capacity.
| Constructor Summary | |
NonblockingPipe(ByteBufferPool bufferPool)
|
|
| Method Summary | |
int |
autoTransferTo()
Transfers as many bytes are possible from this pipe's buffer to the channel specified in the call to setAutoWriteChannel. |
int |
available()
Returns the number of bytes currently available in the pipe. |
void |
clear()
|
void |
closeForWriting()
Called to signal that no more data will be transferred from an external channel to the pipe. |
java.io.InputStream |
getInputStream()
Returns an input stream through which the contents of the pipe can be read. |
java.io.OutputStream |
getOutputStream()
Returns an output stream through which the contents of the pipe can be written. |
boolean |
isExhausted()
Returns true if the pipe contains no data, and is closed for writing. |
void |
setAutoWriteChannel(java.nio.channels.WritableByteChannel channel,
ChannelWriteListener listener)
Sets a writable byte channel to which all writes on the output stream are automatically transferred whenever an internal pipe buffer is ready. |
int |
transferFrom(java.nio.ByteBuffer srcbuf,
int maxbytes)
Transfers as many bytes are possible from the specified byte buffer to this pipe's buffer. |
int |
transferFrom(java.nio.channels.ReadableByteChannel channel)
|
int |
transferFrom(java.nio.channels.ReadableByteChannel channel,
int maxbytes)
Transfers as many bytes are possible from the specified channel to this pipe's buffer. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public NonblockingPipe(ByteBufferPool bufferPool)
| Method Detail |
public void setAutoWriteChannel(java.nio.channels.WritableByteChannel channel,
ChannelWriteListener listener)
channel - the channel to which bytes are transferred automaticallylistener - a listener that gets notified of closing the output
stream as well as of any IOExceptions that are thrown during the channel
write operations.public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public int available()
public boolean isExhausted()
public int autoTransferTo()
throws java.io.IOException
java.io.IOException
public int transferFrom(java.nio.channels.ReadableByteChannel channel)
throws java.io.IOException
java.io.IOException
public int transferFrom(java.nio.channels.ReadableByteChannel channel,
int maxbytes)
throws java.io.IOException
closeForWriting() to indicate you have written
all data to the pipe (or alternatively, you can close the pipe's
output stream to achieve the same effect).
channel - the channel to transfer bytes frommaxbytes - maximum number of bytes to transfer
java.io.IOException
public int transferFrom(java.nio.ByteBuffer srcbuf,
int maxbytes)
throws java.io.IOException
closeForWriting() to indicate
you have written all data to the pipe (or alternatively, you can close
the pipe's output stream to achieve the same effect).
srcbuf - the buffer to transfer bytes frommaxbytes - maximum number of bytes to transfer
java.io.IOExceptionpublic void clear()
public void closeForWriting()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||