Package org.eclipse.jetty.io
Class ByteBufferAggregator
java.lang.Object
org.eclipse.jetty.io.ByteBufferAggregator
Aggregates data into a single ByteBuffer of a specified maximum size.
The buffer automatically grows as data is written to it, up until it reaches the specified maximum size. Once the buffer is full, the aggregator will not aggregate any more bytes until its buffer is taken out, after which a new aggregate/take buffer cycle can start.
The buffers are taken from the supplied ByteBufferPool
or freshly allocated if one is not supplied.
-
Constructor Summary
ConstructorDescriptionByteBufferAggregator
(ByteBufferPool bufferPool, boolean direct, int startSize, int maxSize) Creates a ByteBuffer aggregator. -
Method Summary
Modifier and TypeMethodDescriptionboolean
aggregate
(ByteBuffer buffer) Aggregates the given ByteBuffer.int
length()
Get the currently aggregated length.Takes the buffer out of the aggregator.toString()
-
Constructor Details
-
ByteBufferAggregator
Creates a ByteBuffer aggregator.- Parameters:
bufferPool
- TheByteBufferPool
from which to acquire the buffersdirect
- whether to get direct buffersstartSize
- the starting size of the buffermaxSize
- the maximum size of the buffer which must be greater thanstartSize
-
-
Method Details
-
length
public int length()Get the currently aggregated length.- Returns:
- The current total aggregated bytes.
-
aggregate
Aggregates the given ByteBuffer. This copies bytes up to the specified maximum size, at which time this method returnstrue
andtakeRetainableByteBuffer()
must be called for this method to accept aggregating again.- Parameters:
buffer
- the buffer to copy into this aggregator; its position is updated according to the number of aggregated bytes- Returns:
- true if the aggregator's buffer is full and should be taken, false otherwise
-
takeRetainableByteBuffer
Takes the buffer out of the aggregator. Once the buffer has been taken out, the aggregator resets itself and a new buffer will be acquired from the pool during the nextaggregate(ByteBuffer)
call.- Returns:
- the aggregated buffer, or null if nothing has been buffered yet
-
toString
-