|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.healthmarketscience.rmiio.util.PipeBuffer
public class PipeBuffer
Utility class for implementing a pipe which will never block (at the expense of possibly utilizing more memory). This is useful for single threaded pipe implementations (the java.io pipe implementations require separate threads for reading and writing due to the possibility of the writer or reader blocking). Additionally, packet based read/write support is implemented, which can be a significant speed advantage when working in situations were buffers can be passed around instead of copied (e.g. RMI usage). In general, this implementation favors speed over memory usage, so buffers will not be copied if at all possible, even if they are not making the most efficient usage of memory. This class has no synchronization as it is designed for use by a single thread.
Nested Class Summary | |
---|---|
static class |
PipeBuffer.InputStreamAdapter
PacketInputStream implementation which reads from a PipeBuffer. |
static class |
PipeBuffer.OutputStreamAdapter
PacketOutputStream implementation which writes to a PipeBuffer. |
Field Summary | |
---|---|
static int |
DEFAULT_PACKET_SIZE
default target size of packets returned from packet related methods and internal buffer allocation |
Constructor Summary | |
---|---|
PipeBuffer()
|
|
PipeBuffer(int packetSize)
|
Method Summary | |
---|---|
void |
clear()
Clears all remaining bytes from this buffer and releases all internal buffers. |
void |
closeRead()
Indicates that the "reader" of this PipeBuffer is finished. |
void |
closeWrite()
Indicates that the "writer" of this PipeBuffer is finished. |
int |
getPacketSize()
|
boolean |
hasRemaining()
|
boolean |
isReadClosed()
|
boolean |
isWriteClosed()
|
int |
packetsAvailable()
|
void |
read(byte[] buf,
int pos,
int len)
Reads the given number of bytes into the given buffer starting at the given position. |
byte[] |
readPacket()
Reads a packet of data from this buffer. |
long |
remaining()
|
void |
skip(long len)
Skips the given number of bytes in this buffer. |
void |
write(byte[] buf,
int pos,
int len)
Writes the given number of bytes from the given buffer starting at the given position. |
void |
writePacket(byte[] buf,
int pos,
int len)
Writes a packet of data to this buffer, where the initial data in the packet will start at the given position and have the given length. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_PACKET_SIZE
Constructor Detail |
---|
public PipeBuffer()
public PipeBuffer(int packetSize)
packetSize
- "suggested" size for packets returned from readPacket()
as well as buffers allocated internally.
in the interest of speed, actual packet sizes and
internal buffer sizes may vary from this value.Method Detail |
---|
public boolean isReadClosed()
closeRead()
has been calledpublic void closeRead()
isReadClosed()
to return true
from now on. Useful
for coordinating between reader and writer of the PipeBuffer.
public boolean isWriteClosed()
closeWrite()
has been calledpublic void closeWrite()
isWriteClosed()
to return true
from now on. Useful
for coordinating between reader and writer of the PipeBuffer.
public int getPacketSize()
public boolean hasRemaining()
true
if there are bytes to read in the buffer,
false
otherwisepublic long remaining()
public byte[] readPacket()
public void read(byte[] buf, int pos, int len)
public void skip(long len)
public void writePacket(byte[] buf, int pos, int len)
public void write(byte[] buf, int pos, int len)
public void clear()
public int packetsAvailable()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |