Class RetainableByteBuffer.Wrapper
java.lang.Object
org.eclipse.jetty.io.Retainable.Wrapper
org.eclipse.jetty.io.RetainableByteBuffer.Wrapper
- All Implemented Interfaces:
 Retainable, RetainableByteBuffer, RetainableByteBuffer.Mutable
- Enclosing interface:
 RetainableByteBuffer
public static class RetainableByteBuffer.Wrapper
extends Retainable.Wrapper
implements RetainableByteBuffer.Mutable
A wrapper for 
RetainableByteBuffer instances- 
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
Constructors - 
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.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 bytes) 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 buffer) Appends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.booleanappendTo(RetainableByteBuffer buffer) Appends 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 independentintget(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 indexGet the wrapped, notnull,ByteBuffer.booleanbooleanisDirect()booleanisEmpty()booleanisFull()booleanReturns whetherRetainable.retain()has been called at least one more time thanRetainable.release().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.intlongskip(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()toString()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 Retainable.Wrapper
canRetain, getRetained, release, retainMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Retainable
canRetain, getRetained, release, retainMethods inherited from interface RetainableByteBuffer
get, isMutable, limit, maxSize, size, take, take, takeByteArray, takeFrom, writeToMethods inherited from interface RetainableByteBuffer.Mutable
put 
- 
Constructor Details
- 
Wrapper
 
 - 
 - 
Method Details
- 
getWrapped
- Overrides:
 getWrappedin classRetainable.Wrapper
 - 
isRetained
public boolean isRetained()Description copied from interface:RetainableReturns whether
Retainable.retain()has been called at least one more time thanRetainable.release().- Specified by:
 isRetainedin interfaceRetainable- Overrides:
 isRetainedin classRetainable.Wrapper- Returns:
 - whether this buffer is retained
 
 - 
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 
 - 
isDirect
public boolean isDirect()- Specified by:
 isDirectin interfaceRetainableByteBuffer- Returns:
 - whether the 
ByteBufferis direct 
 - 
remaining
public int remaining()- Specified by:
 remainingin interfaceRetainableByteBuffer- Returns:
 - the number of remaining bytes in the 
ByteBuffer - See Also:
 
 - 
hasRemaining
public boolean hasRemaining()- Specified by:
 hasRemainingin interfaceRetainableByteBuffer- Returns:
 - whether the 
ByteBufferhas remaining bytes 
 - 
capacity
public int capacity()- Specified by:
 capacityin interfaceRetainableByteBuffer- Returns:
 - the capacity
 - See Also:
 
 - 
clear
public void clear()- Specified by:
 clearin interfaceRetainableByteBuffer- See Also:
 
 - 
toString
- Overrides:
 toStringin classRetainable.Wrapper
 - 
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:
 buffer- 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:
 buffer- 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:
 
 - 
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
 
 - 
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. 
 - 
get
public byte get(long index) 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
 
 - 
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
 
 - 
isEmpty
public boolean isEmpty()- Specified by:
 isEmptyin interfaceRetainableByteBuffer- Returns:
 - whether the 
ByteBufferhas remaining bytes left for reading 
 - 
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.- Throws:
 BufferOverflowException- – If there is insufficient space in this buffer for the remaining bytes in the source buffer- See Also:
 
 - 
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
 
 - 
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:
 
 - 
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:
 
 - 
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:
 
 - 
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. 
 - 
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. 
 - 
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.
 - Throws:
 ReadOnlyBufferException- if this buffer is read only.- 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:
 bytes- the retainable byte buffer to copy from, which is consumed.- Returns:
 - true if all bytes of the given buffer were copied, false otherwise.
 - Throws:
 ReadOnlyBufferException- if this buffer is read only.- 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.
 - 
toDetailString
- Specified by:
 toDetailStringin interfaceRetainableByteBuffer- Returns:
 - A string showing the info and detail about this buffer, as well as a summary of the contents
 
 
 -