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 org.eclipse.jetty.io.Retainable
Retainable.ReferenceCounter, Retainable.Wrapper
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.RetainableByteBuffer
RetainableByteBuffer.Abstract, RetainableByteBuffer.DynamicCapacity, RetainableByteBuffer.EmptyRetainableByteBuffer, RetainableByteBuffer.FixedCapacity, RetainableByteBuffer.Mutable, RetainableByteBuffer.NonRetainableByteBuffer, RetainableByteBuffer.Pooled, RetainableByteBuffer.Wrapper
-
Field Summary
Fields inherited from interface org.eclipse.jetty.io.Retainable
NON_RETAINABLE
Fields inherited from interface org.eclipse.jetty.io.RetainableByteBuffer
EMPTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(ByteBuffer bytes) Add the passedByteBuffer
to this buffer, growing this buffer if necessary and possible.add
(RetainableByteBuffer bytes) Add the passedRetainableByteBuffer
to this buffer, growing this buffer if necessary and possible.boolean
append
(ByteBuffer bytes) Copies the contents of the given byte buffer to the end of this buffer, growing this buffer if necessary and possible.boolean
append
(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.boolean
appendTo
(ByteBuffer buffer) Appends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.boolean
appendTo
(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.Mutable
API.int
capacity()
void
clear()
copy()
Creates a deep copy of this RetainableByteBuffer that is entirely independentint
get
(byte[] bytes, int offset, int length) Consumes and copies the bytes from this RetainableByteBuffer to the given byte array.byte
get
(long index) Returns a byte from this RetainableByteBuffer at a specific indexGet the wrapped, notnull
,ByteBuffer
.boolean
boolean
isDirect()
boolean
isEmpty()
boolean
isFull()
boolean
Returns whetherRetainable.retain()
has been called at least one more time thanRetainable.release()
.put
(byte b) Put abyte
to the buffer, growing this buffer if necessary and possible.put
(byte[] bytes, int offset, int length) Put abyte
array to the buffer, growing this buffer if necessary and possible.put
(long index, byte b) Put abyte
to the buffer at a given index.putInt
(int i) Put anint
to the buffer, growing this buffer if necessary and possible.putLong
(long l) Put along
to the buffer, growing this buffer if necessary and possible.putShort
(short s) Put ashort
to the buffer, growing this buffer if necessary and possible.void
putTo
(ByteBuffer toInfillMode) Consumes and puts the contents of this retainable byte buffer at the end of the given byte buffer.int
long
skip
(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.long
space()
toString()
void
writeTo
(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 org.eclipse.jetty.io.Retainable.Wrapper
canRetain, getRetained, release, retain
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.io.Retainable
canRetain, getRetained, release, retain
Methods inherited from interface org.eclipse.jetty.io.RetainableByteBuffer
get, isMutable, limit, maxSize, size, take, take, takeByteArray, takeFrom, writeTo
Methods inherited from interface org.eclipse.jetty.io.RetainableByteBuffer.Mutable
put
-
Constructor Details
-
Wrapper
-
-
Method Details
-
getWrapped
- Overrides:
getWrapped
in classRetainable.Wrapper
-
isRetained
public boolean isRetained()Description copied from interface:Retainable
Returns whether
Retainable.retain()
has been called at least one more time thanRetainable.release()
.- Specified by:
isRetained
in interfaceRetainable
- Overrides:
isRetained
in classRetainable.Wrapper
- Returns:
- whether this buffer is retained
-
getByteBuffer
Description copied from interface:RetainableByteBuffer
Get 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:
getByteBuffer
in interfaceRetainableByteBuffer
- Returns:
- the wrapped, not
null
,ByteBuffer
-
isDirect
public boolean isDirect()- Specified by:
isDirect
in interfaceRetainableByteBuffer
- Returns:
- whether the
ByteBuffer
is direct
-
remaining
public int remaining()- Specified by:
remaining
in interfaceRetainableByteBuffer
- Returns:
- the number of remaining bytes in the
ByteBuffer
- See Also:
-
hasRemaining
public boolean hasRemaining()- Specified by:
hasRemaining
in interfaceRetainableByteBuffer
- Returns:
- whether the
ByteBuffer
has remaining bytes
-
capacity
public int capacity()- Specified by:
capacity
in interfaceRetainableByteBuffer
- Returns:
- the capacity
- See Also:
-
clear
public void clear()- Specified by:
clear
in interfaceRetainableByteBuffer
- See Also:
-
toString
- Overrides:
toString
in classRetainable.Wrapper
-
appendTo
Description copied from interface:RetainableByteBuffer
Appends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.- Specified by:
appendTo
in interfaceRetainableByteBuffer
- Parameters:
buffer
- The buffer to append bytes to, whose limit will be updated.- Returns:
true
if all bytes in this buffer are able to be appended.- See Also:
-
appendTo
Description copied from interface:RetainableByteBuffer
Appends and consumes the contents of this buffer to the passed buffer, limited by the capacity of the target buffer.- Specified by:
appendTo
in interfaceRetainableByteBuffer
- Parameters:
buffer
- The buffer to append bytes to, whose limit will be updated.- Returns:
true
if all bytes in this buffer are able to be appended.- See Also:
-
copy
Description copied from interface:RetainableByteBuffer
Creates a deep copy of this RetainableByteBuffer that is entirely independent- Specified by:
copy
in interfaceRetainableByteBuffer
- Returns:
- A copy of this RetainableByteBuffer
-
slice
Description copied from interface:RetainableByteBuffer
Get a partial slice of the buffer. This is equivalent toRetainableByteBuffer.slice()
.RetainableByteBuffer.limit(long)
, but may be implemented more efficiently.- Specified by:
slice
in 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
RetainableByteBuffer
sharing the firstlength
bytes of this buffers data and reference count, but with independent position. The buffer isretained
by this call.
-
get
public byte get(long index) Description copied from interface:RetainableByteBuffer
Returns a byte from this RetainableByteBuffer at a specific index- Specified by:
get
in 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:RetainableByteBuffer
Consumes and copies the bytes from this RetainableByteBuffer to the given byte array.- Specified by:
get
in 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:
isEmpty
in interfaceRetainableByteBuffer
- Returns:
- whether the
ByteBuffer
has remaining bytes left for reading
-
putTo
Description copied from interface:RetainableByteBuffer
Consumes and puts the contents of this retainable byte buffer at the end of the given byte buffer.- Specified by:
putTo
in 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:RetainableByteBuffer
Skips, advancing the ByteBuffer position, the given number of bytes.
- Specified by:
skip
in interfaceRetainableByteBuffer
- Parameters:
length
- the maximum number of bytes to skip- Returns:
- the number of bytes actually skipped
-
slice
Description copied from interface:RetainableByteBuffer
Get a slice of the buffer.- Specified by:
slice
in interfaceRetainableByteBuffer
- Returns:
- A sliced
RetainableByteBuffer
sharing this buffers data and reference count, but with independent position. The buffer isretained
by this call. - See Also:
-
writeTo
Description copied from interface:RetainableByteBuffer
Asynchronously writes and consumes the contents of this retainable byte buffer into the given sink.- Specified by:
writeTo
in 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:RetainableByteBuffer
Access this buffer via theRetainableByteBuffer.Mutable
API. Note that theRetainableByteBuffer.Mutable
API may be backed by an immutableByteBuffer
.- Specified by:
asMutable
in interfaceRetainableByteBuffer
- Returns:
- An
RetainableByteBuffer.Mutable
representation of this buffer with same data and pointers. - See Also:
-
isFull
public boolean isFull()- Specified by:
isFull
in 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:
space
in 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.Mutable
Copies the contents of the given byte buffer to the end of this buffer, growing this buffer if necessary and possible.- Specified by:
append
in 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.Mutable
Retain 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:
append
in 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.Mutable
Add the passedByteBuffer
to this buffer, growing this buffer if necessary and possible. The sourceByteBuffer
is 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:
add
in interfaceRetainableByteBuffer.Mutable
- Parameters:
bytes
- the byte buffer to add, which is passed by reference and is not necessarily consumed by the add.- Returns:
this
buffer.- 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.Mutable
Add the passedRetainableByteBuffer
to this buffer, growing this buffer if necessary and possible. The sourceRetainableByteBuffer
is 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 useadd
rather 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:
add
in interfaceRetainableByteBuffer.Mutable
- Parameters:
bytes
- the byte buffer to add, which is passed by reference and is not necessarily consumed by the add.- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read only.BufferOverflowException
- if this buffer cannot fit the byte
-
put
Description copied from interface:RetainableByteBuffer.Mutable
Put abyte
to the buffer, growing this buffer if necessary and possible.- Specified by:
put
in interfaceRetainableByteBuffer.Mutable
- Parameters:
b
- thebyte
to put- Returns:
this
buffer.
-
put
Description copied from interface:RetainableByteBuffer.Mutable
Put abyte
to the buffer at a given index.- Specified by:
put
in interfaceRetainableByteBuffer.Mutable
- Parameters:
index
- The index relative to the current start of unconsumed data in the buffer.b
- thebyte
to put- Returns:
this
buffer.
-
putShort
Description copied from interface:RetainableByteBuffer.Mutable
Put ashort
to the buffer, growing this buffer if necessary and possible.- Specified by:
putShort
in interfaceRetainableByteBuffer.Mutable
- Parameters:
s
- theshort
to put- Returns:
this
buffer.
-
putInt
Description copied from interface:RetainableByteBuffer.Mutable
Put anint
to the buffer, growing this buffer if necessary and possible.- Specified by:
putInt
in interfaceRetainableByteBuffer.Mutable
- Parameters:
i
- theint
to put- Returns:
this
buffer.
-
putLong
Description copied from interface:RetainableByteBuffer.Mutable
Put along
to the buffer, growing this buffer if necessary and possible.- Specified by:
putLong
in interfaceRetainableByteBuffer.Mutable
- Parameters:
l
- thelong
to put- Returns:
this
buffer.
-
put
Description copied from interface:RetainableByteBuffer.Mutable
Put abyte
array to the buffer, growing this buffer if necessary and possible.- Specified by:
put
in interfaceRetainableByteBuffer.Mutable
- Parameters:
bytes
- thebyte
array to putoffset
- the offset into the arraylength
- the length in bytes to put- Returns:
this
buffer.
-
toDetailString
- Specified by:
toDetailString
in interfaceRetainableByteBuffer
- Returns:
- A string showing the info and detail about this buffer, as well as a summary of the contents
-