public class WriteBuffers extends Buffers
Buffers
only store 1 pending write, WriteBuffers store N pending writes. When the bounded buffer is
full, additional writes will be discarded.
All pending writes are stored in the bufs array, and position and limit point to the current start and end of
writable buffers.
Completed writes are nulled, and when the end of the array is reached, position and limit wrap around, possibly
copying pending writes to the head of the array. Position and limit only advance when an entire buffer has been
written successfully; partial writes don't advance them.
Like Buffers, WriteBuffers is not synchronized.
Invariant: 0 <= position <= limitModifier and Type | Field and Description |
---|---|
protected int |
limit |
protected int |
position |
Constructor and Description |
---|
WriteBuffers() |
WriteBuffers(java.nio.ByteBuffer data) |
WriteBuffers(int capacity)
Creates a WriteBuffers of capacity * 2 elements (capacity {length/data} pairs)
|
Modifier and Type | Method and Description |
---|---|
protected void |
add(java.nio.ByteBuffer buf) |
int |
limit() |
protected static java.nio.ByteBuffer |
makeLengthBuffer(java.nio.ByteBuffer buf) |
protected boolean |
makeSpace() |
protected boolean |
nullData()
Looks at all buffers in range [position ..
|
int |
position() |
java.lang.String |
print() |
int |
remaining() |
int |
size()
Returns the number of elements that have not yet been written
|
protected boolean |
spaceAvailable() |
java.lang.String |
toString() |
boolean |
write(java.nio.channels.SocketChannel ch)
Tries to complete a previous (unfinished) write
|
boolean |
write(java.nio.channels.SocketChannel ch,
java.nio.ByteBuffer buf)
Writes the length and data with a gathering write
|
public WriteBuffers()
public WriteBuffers(int capacity)
public WriteBuffers(java.nio.ByteBuffer data)
public int position()
public int limit()
public boolean write(java.nio.channels.SocketChannel ch, java.nio.ByteBuffer buf) throws java.lang.Exception
Buffers
write
in class Buffers
ch
- The channel to write tobuf
- The data buffer. Note that Buffer.position
needs to be at the start of the data to be writtenjava.lang.Exception
- Thrown if the write failedpublic boolean write(java.nio.channels.SocketChannel ch) throws java.lang.Exception
Buffers
public int size()
public java.lang.String print()
protected boolean spaceAvailable()
protected boolean makeSpace()
protected void add(java.nio.ByteBuffer buf)
protected boolean nullData()
protected static java.nio.ByteBuffer makeLengthBuffer(java.nio.ByteBuffer buf)
Copyright © 1998-2020 Red Hat. All Rights Reserved.