Top Description Fields Constructors Methods
org.eclipse.jetty.io

public Class ByteBufferAggregator

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, org.eclipse.jetty.util.BufferUtil, org.slf4j.Logger, .LoggerFactory

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.

Field Summary

Modifier and TypeField and Description
private int
private final ByteBufferPool
private int
private final boolean
private final int
private RetainableByteBuffer
private static final Logger

Constructor Summary

AccessConstructor and Description
public
ByteBufferAggregator(ByteBufferPool
The ByteBufferPool from which to acquire the buffers
bufferPool
,
boolean
whether to get direct buffers
direct
,
int
the starting size of the buffer
startSize
,
int
the maximum size of the buffer which must be greater than startSize
maxSize
)

Creates a ByteBuffer aggregator.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the aggregator's buffer is full and should be taken, false otherwise
aggregate
(ByteBuffer
the buffer to copy into this aggregator; its position is updated according to the number of aggregated bytes
buffer
)

Aggregates the given ByteBuffer.

private static int
public int

Returns:

The current total aggregated bytes.
length
()

Get the currently aggregated length.

public RetainableByteBuffer

Returns:

the aggregated buffer, or null if nothing has been buffered yet
takeRetainableByteBuffer
()

Takes the buffer out of the aggregator.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
tryExpandBufferCapacity(int remaining)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_aggregatedSizeback to summary
private int _aggregatedSize
_bufferPoolback to summary
private final ByteBufferPool _bufferPool
_currentSizeback to summary
private int _currentSize
_directback to summary
private final boolean _direct
_maxSizeback to summary
private final int _maxSize
_retainableByteBufferback to summary
private RetainableByteBuffer _retainableByteBuffer
LOGback to summary
private static final Logger LOG

Constructor Detail

ByteBufferAggregatorback to summary
public ByteBufferAggregator(ByteBufferPool bufferPool, boolean direct, int startSize, int maxSize)

Creates a ByteBuffer aggregator.

Parameters
bufferPool:ByteBufferPool

The ByteBufferPool from which to acquire the buffers

direct:boolean

whether to get direct buffers

startSize:int

the starting size of the buffer

maxSize:int

the maximum size of the buffer which must be greater than startSize

Method Detail

aggregateback to summary
public boolean aggregate(ByteBuffer buffer)

Aggregates the given ByteBuffer. This copies bytes up to the specified maximum size, at which time this method returns true and takeRetainableByteBuffer() must be called for this method to accept aggregating again.

Parameters
buffer:ByteBuffer

the buffer to copy into this aggregator; its position is updated according to the number of aggregated bytes

Returns:boolean

true if the aggregator's buffer is full and should be taken, false otherwise

ceilToNextPowerOfTwoback to summary
private static int ceilToNextPowerOfTwo(int val)
lengthback to summary
public int length()

Get the currently aggregated length.

Returns:int

The current total aggregated bytes.

takeRetainableByteBufferback to summary
public RetainableByteBuffer 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 next aggregate(ByteBuffer) call.

Returns:RetainableByteBuffer

the aggregated buffer, or null if nothing has been buffered yet

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
tryExpandBufferCapacityback to summary
private void tryExpandBufferCapacity(int remaining)