Class RetainableByteBuffer.DynamicCapacity
java.lang.Object
org.eclipse.jetty.io.Retainable.Wrapper
org.eclipse.jetty.io.RetainableByteBuffer.Abstract
org.eclipse.jetty.io.RetainableByteBuffer.DynamicCapacity
- All Implemented Interfaces:
 Retainable, RetainableByteBuffer, RetainableByteBuffer.Mutable
- Enclosing interface:
 RetainableByteBuffer
public static class RetainableByteBuffer.DynamicCapacity
extends RetainableByteBuffer.Abstract
implements RetainableByteBuffer.Mutable
An 
RetainableByteBuffer.Mutable RetainableByteBuffer that can grow its capacity, backed by a chain of ByteBuffer,
which may grow either by aggregation and/or retention.
When retaining, a chain of zero copy buffers are kept.
When aggregating, this class avoid repetitive copies of the same data during growth by aggregating
to a chain of buffers, which are only copied to a single buffer if required.
If the minRetainSize is {code 0}, then appending to this buffer will always retain and accumulate.
If the minRetainSize is Integer.MAX_VALUE, then appending to this buffer will always aggregate.- 
Nested Class Summary
Nested classes/interfaces inherited from interface Retainable
Retainable.ReferenceCounter, Retainable.WrapperNested classes/interfaces inherited from interface RetainableByteBuffer
RetainableByteBuffer.Abstract, RetainableByteBuffer.DynamicCapacity, RetainableByteBuffer.EmptyRetainableByteBuffer, RetainableByteBuffer.FixedCapacity, RetainableByteBuffer.Mutable, RetainableByteBuffer.NonRetainableByteBuffer, RetainableByteBuffer.Pooled, RetainableByteBuffer.Wrapper - 
Field Summary
Fields inherited from interface Retainable
NON_RETAINABLEFields inherited from interface RetainableByteBuffer
EMPTY - 
Constructor Summary
ConstructorsConstructorDescriptionA buffer with no size limit and default aggregation and retention settings.DynamicCapacity(ByteBufferPool.Sized sizedPool) DynamicCapacity(ByteBufferPool.Sized sizedPool, long maxSize) DynamicCapacity(ByteBufferPool.Sized sizedPool, long maxSize, int minRetainSize) DynamicCapacity(ByteBufferPool pool, boolean direct, long maxSize) DynamicCapacity(ByteBufferPool pool, boolean direct, long maxSize, int aggregationSize) DynamicCapacity(ByteBufferPool pool, boolean direct, long maxSize, int aggregationSize, int minRetainSize)  - 
Method Summary
Modifier and TypeMethodDescriptionadd(ByteBuffer bytes) Add the passedByteBufferto this buffer, growing this buffer if necessary and possible.add(RetainableByteBuffer bytes) Add the passedRetainableByteBufferto this buffer, growing this buffer if necessary and possible.protected voidaddExtraStringInfo(StringBuilder builder) protected voidaddValueMarker(StringBuilder builder, boolean beginning) protected voidaddValueString(StringBuilder builder) booleanappend(ByteBuffer bytes) Copies the contents of the given byte buffer to the end of this buffer, growing this buffer if necessary and possible.booleanappend(RetainableByteBuffer retainableBytes) Retain or copy the contents of the given retainable byte buffer to the end of this buffer, growing this buffer if necessary and possible.booleanappendTo(ByteBuffer to) Appends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.booleanAppends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.Access this buffer via theRetainableByteBuffer.MutableAPI.intcapacity()voidclear()copy()Creates a deep copy of this RetainableByteBuffer that is entirely independentbyteget()Consumes and returns a byte from this RetainableByteBufferintget(byte[] bytes, int offset, int length) Consumes and copies the bytes from this RetainableByteBuffer to the given byte array.byteget(long index) Returns a byte from this RetainableByteBuffer at a specific indexintGet the wrapped, notnull,ByteBuffer.longintbooleanbooleanisDirect()booleanisFull()booleanCheck if the underlying implementation is mutable.voidlimit(long limit) Limit this buffer's contents to the size.longmaxSize()put(byte b) Put abyteto the buffer, growing this buffer if necessary and possible.put(byte[] bytes, int offset, int length) Put abytearray to the buffer, growing this buffer if necessary and possible.put(long index, byte b) Put abyteto the buffer at a given index.putInt(int i) Put anintto the buffer, growing this buffer if necessary and possible.putLong(long l) Put alongto the buffer, growing this buffer if necessary and possible.putShort(short s) Put ashortto the buffer, growing this buffer if necessary and possible.voidputTo(ByteBuffer toInfillMode) Consumes and puts the contents of this retainable byte buffer at the end of the given byte buffer.booleanrelease()Releases this resource, potentially decrementing a reference count (if any).intlongsize()longskip(long length) Skips, advancing the ByteBuffer position, the given number of bytes.slice()Get a slice of the buffer.slice(long length) Get a partial slice of the buffer.longspace()take(long length) Take the contents of this buffer, from the head, leaving remaining bytes in this buffer.byte[]Take the contents of this buffer, leaving it clear and independent.takeFrom(long skip) Take the contents of this buffer, from the tail, leaving remaining bytes in this buffer.voidwriteTo(Content.Sink sink, boolean last, Callback callback) Asynchronously writes and consumes the contents of this retainable byte buffer into the given sink.Methods inherited from class RetainableByteBuffer.Abstract
addStringInfo, toDetailString, toStringMethods inherited from class Retainable.Wrapper
canRetain, getRetained, getWrapped, isRetained, retainMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Retainable
canRetain, getRetained, isRetained, retainMethods inherited from interface RetainableByteBuffer
isEmpty, take, toDetailString, writeToMethods inherited from interface RetainableByteBuffer.Mutable
put 
- 
Constructor Details
- 
DynamicCapacity
public DynamicCapacity()A buffer with no size limit and default aggregation and retention settings. - 
DynamicCapacity
- Parameters:
 sizedPool- The pool from which to allocate buffers, withByteBufferPool.Sized.isDirect()configured andByteBufferPool.Sized.getSize()used for the size of aggregation buffers.
 - 
DynamicCapacity
- Parameters:
 sizedPool- The pool from which to allocate buffers, withByteBufferPool.Sized.isDirect()configured andByteBufferPool.Sized.getSize()used for the size of aggregation buffers.maxSize- The maximum length of the accumulated buffers or -1 for 2GB limit
 - 
DynamicCapacity
- Parameters:
 sizedPool- The pool from which to allocate buffers, withByteBufferPool.Sized.isDirect()configured andByteBufferPool.Sized.getSize()used for the size of aggregation buffers.maxSize- The maximum length of the accumulated buffers or -1 for 2GB limitminRetainSize- The minimal size of aRetainableByteBufferbefore it will be retained; or 0 to always retain; or -1 for a heuristic;
 - 
DynamicCapacity
- Parameters:
 pool- The pool from which to allocate buffers
 - 
DynamicCapacity
- Parameters:
 pool- The pool from which to allocate buffersdirect- true if direct buffers should be usedmaxSize- The maximum length of the accumulated buffers or -1 for 2GB limit
 - 
DynamicCapacity
- Parameters:
 pool- The pool from which to allocate buffersdirect- true if direct buffers should be usedmaxSize- The maximum length of the accumulated buffers or -1 for 2GB limitaggregationSize- The default size of aggregation buffers; or 0 for no aggregation growth; or -1 for a default size. If theaggregationSizeis 0 and themaxSizeis less thatInteger.MAX_VALUE, then a single aggregation buffer may be allocated and the class will behave similarly toRetainableByteBuffer.FixedCapacity.
 - 
DynamicCapacity
public DynamicCapacity(ByteBufferPool pool, boolean direct, long maxSize, int aggregationSize, int minRetainSize) - Parameters:
 pool- The pool from which to allocate buffersdirect- true if direct buffers should be usedmaxSize- The maximum length of the accumulated buffers or -1 for 2GB limitaggregationSize- The default size of aggregation buffers; or 0 for no aggregation growth; or -1 for a default size. If theaggregationSizeis 0 and themaxSizeis less thatInteger.MAX_VALUE, then a single aggregation buffer may be allocated and the class will behave similarly toRetainableByteBuffer.FixedCapacity.minRetainSize- The minimal size of aRetainableByteBufferbefore it will be retained; or 0 to always retain; or -1 for a heuristic;
 
 - 
 - 
Method Details
- 
getMaxSize
public long getMaxSize() - 
getAggregationSize
public int getAggregationSize() - 
getMinRetainSize
public int getMinRetainSize() - 
isMutable
public boolean isMutable()Description copied from interface:RetainableByteBufferCheck if the underlying implementation is mutable. Note that the immutableRetainableByteBufferAPI may be backed by a mutableByteBufferor theRetainableByteBuffer.MutableAPI may be backed by an immutableByteBuffer.- Specified by:
 isMutablein interfaceRetainableByteBuffer- Returns:
 - whether this buffers implementation is mutable
 - See Also:
 
 - 
asMutable
Description copied from interface:RetainableByteBufferAccess this buffer via theRetainableByteBuffer.MutableAPI. Note that theRetainableByteBuffer.MutableAPI may be backed by an immutableByteBuffer.- Specified by:
 asMutablein interfaceRetainableByteBuffer- Returns:
 - An 
RetainableByteBuffer.Mutablerepresentation of this buffer with same data and pointers. - See Also:
 
 - 
getByteBuffer
Description copied from interface:RetainableByteBufferGet the wrapped, notnull,ByteBuffer.If the implementation contains multiple buffers, they are coalesced to a single buffer before being returned. If the content is too large for a single
ByteBuffer, then the content should be access withRetainableByteBuffer.writeTo(Content.Sink, boolean).- Specified by:
 getByteBufferin interfaceRetainableByteBuffer- Returns:
 - the wrapped, not 
null,ByteBuffer - Throws:
 BufferOverflowException- if the contents is too large for a singleByteBuffer
 - 
take
Description copied from interface:RetainableByteBufferTake the contents of this buffer, from the head, leaving remaining bytes in this buffer. This is similar toRetainableByteBuffer.slice(long)followed by aRetainableByteBuffer.skip(long), but avoids shared data.- Specified by:
 takein interfaceRetainableByteBuffer- Parameters:
 length- The number of bytes to take- Returns:
 - A buffer with the contents of this buffer after limiting bytes, avoiding copies if possible, but with no shared internal buffers.
 
 - 
takeFrom
Description copied from interface:RetainableByteBufferTake the contents of this buffer, from the tail, leaving remaining bytes in this buffer.- Specified by:
 takeFromin interfaceRetainableByteBuffer- Parameters:
 skip- The number of bytes to skip before taking the tail.- Returns:
 - A buffer with the contents of this buffer after skipping bytes, avoiding copies if possible, but with no shared internal buffers.
 
 - 
takeByteArray
public byte[] takeByteArray()Description copied from interface:RetainableByteBufferTake the contents of this buffer, leaving it clear and independent.- Specified by:
 takeByteArrayin interfaceRetainableByteBuffer- Returns:
 - A possibly newly allocated array with the contents of this buffer, avoiding copies if possible.
 
 - 
get
Description copied from interface:RetainableByteBufferConsumes and returns a byte from this RetainableByteBuffer- Specified by:
 getin interfaceRetainableByteBuffer- Returns:
 - the byte
 - Throws:
 BufferUnderflowException- if the buffer is empty.- See Also:
 
 - 
get
Description copied from interface:RetainableByteBufferReturns a byte from this RetainableByteBuffer at a specific index- Specified by:
 getin interfaceRetainableByteBuffer- Parameters:
 index- The index relative to the current start of unconsumed data in the buffer.- Returns:
 - the byte
 - Throws:
 IndexOutOfBoundsException- if the index is too large.
 - 
get
public int get(byte[] bytes, int offset, int length) Description copied from interface:RetainableByteBufferConsumes and copies the bytes from this RetainableByteBuffer to the given byte array.- Specified by:
 getin interfaceRetainableByteBuffer- Parameters:
 bytes- the byte array to copy the bytes intooffset- the offset within the byte arraylength- the maximum number of bytes to copy- Returns:
 - the number of bytes actually copied
 
 - 
isDirect
public boolean isDirect()- Specified by:
 isDirectin interfaceRetainableByteBuffer- Returns:
 - whether the 
ByteBufferis direct 
 - 
hasRemaining
public boolean hasRemaining()- Specified by:
 hasRemainingin interfaceRetainableByteBuffer- Returns:
 - whether the 
ByteBufferhas remaining bytes 
 - 
skip
public long skip(long length) Description copied from interface:RetainableByteBufferSkips, advancing the ByteBuffer position, the given number of bytes.
- Specified by:
 skipin interfaceRetainableByteBuffer- Parameters:
 length- the maximum number of bytes to skip- Returns:
 - the number of bytes actually skipped
 
 - 
limit
public void limit(long limit) Description copied from interface:RetainableByteBufferLimit this buffer's contents to the size.
- Specified by:
 limitin interfaceRetainableByteBuffer- Parameters:
 limit- the new size of the buffer
 - 
slice
Description copied from interface:RetainableByteBufferGet a slice of the buffer.- Specified by:
 slicein interfaceRetainableByteBuffer- Returns:
 - A sliced 
RetainableByteBuffersharing this buffers data and reference count, but with independent position. The buffer isretainedby this call. - See Also:
 
 - 
slice
Description copied from interface:RetainableByteBufferGet a partial slice of the buffer. This is equivalent toRetainableByteBuffer.slice().RetainableByteBuffer.limit(long), but may be implemented more efficiently.- Specified by:
 slicein interfaceRetainableByteBuffer- Parameters:
 length- The number of bytes to slice, which may beyond the limit and less than the capacity, in which case it will ensure some spare capacity in the slice.- Returns:
 - A sliced 
RetainableByteBuffersharing the firstlengthbytes of this buffers data and reference count, but with independent position. The buffer isretainedby this call. 
 - 
space
public long space()- Specified by:
 spacein interfaceRetainableByteBuffer- Returns:
 - the number of bytes that can be added, appended or put into this buffer,
assuming it is 
mutable. 
 - 
isFull
public boolean isFull()- Specified by:
 isFullin interfaceRetainableByteBuffer- Returns:
 - true if no more bytes can be added, appended or put to this buffer,
assuming it is 
mutable. 
 - 
copy
Description copied from interface:RetainableByteBufferCreates a deep copy of this RetainableByteBuffer that is entirely independent- Specified by:
 copyin interfaceRetainableByteBuffer- Returns:
 - A copy of this RetainableByteBuffer
 
 - 
remaining
public int remaining()- Specified by:
 remainingin interfaceRetainableByteBuffer- Returns:
 Integer.MAX_VALUEif the length of thisAccumulatoris greater thanInteger.MAX_VALUE- See Also:
 
 - 
size
public long size()- Specified by:
 sizein interfaceRetainableByteBuffer- Returns:
 - the number of remaining bytes in the 
ByteBuffer - See Also:
 
 - 
capacity
public int capacity()- Specified by:
 capacityin interfaceRetainableByteBuffer- Returns:
 Integer.MAX_VALUEif the maxLength of thisAccumulatoris greater thanInteger.MAX_VALUE.- See Also:
 
 - 
maxSize
public long maxSize()- Specified by:
 maxSizein interfaceRetainableByteBuffer- Returns:
 - the maximum size in bytes.
 - See Also:
 
 - 
release
public boolean release()Description copied from interface:RetainableReleases this resource, potentially decrementing a reference count (if any).
- Specified by:
 releasein interfaceRetainable- Overrides:
 releasein classRetainable.Wrapper- Returns:
 truewhen the reference count goes to zero or if there was no reference count,falseotherwise.
 - 
clear
public void clear()- Specified by:
 clearin interfaceRetainableByteBuffer- See Also:
 
 - 
append
Description copied from interface:RetainableByteBuffer.MutableCopies the contents of the given byte buffer to the end of this buffer, growing this buffer if necessary and possible.- Specified by:
 appendin interfaceRetainableByteBuffer.Mutable- Parameters:
 bytes- the byte buffer to copy from, which is consumed.- Returns:
 - true if all bytes of the given buffer were copied, false otherwise.
 - See Also:
 
 - 
append
Description copied from interface:RetainableByteBuffer.MutableRetain or copy the contents of the given retainable byte buffer to the end of this buffer, growing this buffer if necessary and possible. The implementation will heuristically decide to retain or copy the contents Unlike the similarRetainableByteBuffer.Mutable.add(RetainableByteBuffer), implementations of this method mustRetainable.retain()the passed buffer if they keep a reference to it.- Specified by:
 appendin interfaceRetainableByteBuffer.Mutable- Parameters:
 retainableBytes- the retainable byte buffer to copy from, which is consumed.- Returns:
 - true if all bytes of the given buffer were copied, false otherwise.
 - See Also:
 
 - 
add
public RetainableByteBuffer.Mutable add(ByteBuffer bytes) throws ReadOnlyBufferException, BufferOverflowException Description copied from interface:RetainableByteBuffer.MutableAdd the passedByteBufferto this buffer, growing this buffer if necessary and possible. The sourceByteBufferis passed by reference and the caller gives up "ownership", so implementations of this method may choose to avoid copies by keeping a reference to the buffer.- Specified by:
 addin interfaceRetainableByteBuffer.Mutable- Parameters:
 bytes- the byte buffer to add, which is passed by reference and is not necessarily consumed by the add.- Returns:
 thisbuffer.- Throws:
 ReadOnlyBufferException- if this buffer is read only.BufferOverflowException- if this buffer cannot fit the byte- See Also:
 
 - 
add
public RetainableByteBuffer.Mutable add(RetainableByteBuffer bytes) throws ReadOnlyBufferException, BufferOverflowException Description copied from interface:RetainableByteBuffer.MutableAdd the passedRetainableByteBufferto this buffer, growing this buffer if necessary and possible. The sourceRetainableByteBufferis passed by reference and the caller gives up ownership, so implementations of this method may avoid copies by keeping a reference to the buffer. Unlike the similarRetainableByteBuffer.Mutable.append(RetainableByteBuffer)and contrary to the general rules ofRetainable, implementations of this method need not callRetainable.retain()if keeping a reference, but they must ultimately callRetainable.release()the passed buffer. Callers should useaddrather thanRetainableByteBuffer.Mutable.append(RetainableByteBuffer)if they already have an obligation to release the buffer and wish to delegate that obligation to this buffer.- Specified by:
 addin interfaceRetainableByteBuffer.Mutable- Parameters:
 bytes- the byte buffer to add, which is passed by reference and is not necessarily consumed by the add.- Returns:
 thisbuffer.- Throws:
 ReadOnlyBufferException- if this buffer is read only.BufferOverflowException- if this buffer cannot fit the byte
 - 
put
Description copied from interface:RetainableByteBuffer.MutablePut abyteto the buffer, growing this buffer if necessary and possible.- Specified by:
 putin interfaceRetainableByteBuffer.Mutable- Parameters:
 b- thebyteto put- Returns:
 thisbuffer.
 - 
put
Description copied from interface:RetainableByteBuffer.MutablePut abyteto the buffer at a given index.- Specified by:
 putin interfaceRetainableByteBuffer.Mutable- Parameters:
 index- The index relative to the current start of unconsumed data in the buffer.b- thebyteto put- Returns:
 thisbuffer.
 - 
putShort
Description copied from interface:RetainableByteBuffer.MutablePut ashortto the buffer, growing this buffer if necessary and possible.- Specified by:
 putShortin interfaceRetainableByteBuffer.Mutable- Parameters:
 s- theshortto put- Returns:
 thisbuffer.
 - 
putInt
Description copied from interface:RetainableByteBuffer.MutablePut anintto the buffer, growing this buffer if necessary and possible.- Specified by:
 putIntin interfaceRetainableByteBuffer.Mutable- Parameters:
 i- theintto put- Returns:
 thisbuffer.
 - 
putLong
Description copied from interface:RetainableByteBuffer.MutablePut alongto the buffer, growing this buffer if necessary and possible.- Specified by:
 putLongin interfaceRetainableByteBuffer.Mutable- Parameters:
 l- thelongto put- Returns:
 thisbuffer.
 - 
put
Description copied from interface:RetainableByteBuffer.MutablePut abytearray to the buffer, growing this buffer if necessary and possible.- Specified by:
 putin interfaceRetainableByteBuffer.Mutable- Parameters:
 bytes- thebytearray to putoffset- the offset into the arraylength- the length in bytes to put- Returns:
 thisbuffer.
 - 
appendTo
Description copied from interface:RetainableByteBufferAppends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.- Specified by:
 appendToin interfaceRetainableByteBuffer- Parameters:
 to- The buffer to append bytes to, whose limit will be updated.- Returns:
 trueif all bytes in this buffer are able to be appended.- See Also:
 
 - 
appendTo
Description copied from interface:RetainableByteBufferAppends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.- Specified by:
 appendToin interfaceRetainableByteBuffer- Parameters:
 to- The buffer to append bytes to, whose limit will be updated.- Returns:
 trueif all bytes in this buffer are able to be appended.- See Also:
 
 - 
putTo
Description copied from interface:RetainableByteBufferConsumes and puts the contents of this retainable byte buffer at the end of the given byte buffer.- Specified by:
 putToin interfaceRetainableByteBuffer- Parameters:
 toInfillMode- the destination buffer, whose position is updated.- See Also:
 
 - 
writeTo
Description copied from interface:RetainableByteBufferAsynchronously writes and consumes the contents of this retainable byte buffer into the given sink.- Specified by:
 writeToin interfaceRetainableByteBuffer- Parameters:
 sink- the destination sink.last- true if this is the last write.callback- the callback to call upon the write completion.- See Also:
 
 - 
addExtraStringInfo
- Overrides:
 addExtraStringInfoin classRetainableByteBuffer.Abstract
 - 
addValueString
- Overrides:
 addValueStringin classRetainableByteBuffer.Abstract
 - 
addValueMarker
- Overrides:
 addValueMarkerin classRetainableByteBuffer.Abstract
 
 -