|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
com.threerings.io.ByteBufferOutputStream
com.threerings.io.FramingOutputStream
public class FramingOutputStream
The framing output stream accumulates output into a byte array just
like the byte array output stream, but can then be instructed to send
its contents over a channel, prefixed by the length (written as an
integer) of the entire frame (contents plus length prefix). It does
this efficiently so that data is copied as little as possible and so
that the output stream to which the data is written need not be
buffered because the framed output is written in a single call to
write().
Note: The framing output stream does not synchronize writes to its internal buffer. It is intended to only be accessed from a single thread.
| Field Summary | |
|---|---|
protected static byte[] |
HEADER_PAD
We pad the beginning of our buffer so that we can write the frame length when the time comes. |
| Fields inherited from class com.threerings.io.ByteBufferOutputStream |
|---|
_buffer, INITIAL_BUFFER_SIZE |
| Constructor Summary | |
|---|---|
FramingOutputStream()
|
|
| Method Summary | |
|---|---|
ByteBuffer |
flip()
Flips and returns the buffer. |
ByteBuffer |
frameAndReturnBuffer()
Writes the frame length to the beginning of our buffer and returns it for writing to the appropriate channel. |
void |
reset()
Resets our internal buffer. |
void |
resetFrame()
Resets our internal buffer and prepares to write a new frame. |
| Methods inherited from class com.threerings.io.ByteBufferOutputStream |
|---|
expand, getBuffer, write, write |
| Methods inherited from class java.io.OutputStream |
|---|
close, flush, write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final byte[] HEADER_PAD
| Constructor Detail |
|---|
public FramingOutputStream()
| Method Detail |
|---|
public ByteBuffer flip()
ByteBufferOutputStreamByteBufferOutputStream.reset() to reset the buffer before
writing again.
flip in class ByteBufferOutputStreampublic void reset()
ByteBufferOutputStream
reset in class ByteBufferOutputStreampublic ByteBuffer frameAndReturnBuffer()
resetFrame() when the frame has been written.
public void resetFrame()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||