Interface RetainableByteBuffer.Mutable
- All Superinterfaces:
Retainable
,RetainableByteBuffer
- All Known Implementing Classes:
AbstractRetainableByteBuffer
,ArrayByteBufferPool.Tracking.TrackedBuffer
,RetainableByteBuffer.Abstract
,RetainableByteBuffer.DynamicCapacity
,RetainableByteBuffer.FixedCapacity
,RetainableByteBuffer.NonRetainableByteBuffer
,RetainableByteBuffer.Pooled
,RetainableByteBuffer.Wrapper
- Enclosing interface:
RetainableByteBuffer
Extended
RetainableByteBuffer
API with mutator methods.
The mutator methods come in the following styles:
put
methods are used for putting raw bytes into the buffer and are similar toByteBuffer.put(byte)
etc.Put
methods may be used in fluent style.add
methods are used for handing over an external buffer to be managed by this buffer. External buffers are passed by reference and the caller will not longer manage the added buffer.Add
methods may be used in fluent style.append
methods are used for handing over the content of a buffer to be included in this buffer. The caller may still use the passed buffer and is responsible for eventually releasing it.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Retainable
Retainable.ReferenceCounter
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
-
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.put
(byte b) Put abyte
to the buffer, growing this buffer if necessary and possible.default RetainableByteBuffer.Mutable
put
(byte[] bytes) Put abyte
array 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.Methods inherited from interface org.eclipse.jetty.io.Retainable
canRetain, getRetained, isRetained, release, retain
Methods inherited from interface org.eclipse.jetty.io.RetainableByteBuffer
appendTo, appendTo, asMutable, capacity, clear, copy, get, get, get, getByteBuffer, hasRemaining, isDirect, isEmpty, isFull, isMutable, limit, maxSize, putTo, remaining, size, skip, slice, slice, space, take, take, takeByteArray, takeFrom, toDetailString, writeTo, writeTo
-
Method Details
-
add
RetainableByteBuffer.Mutable add(ByteBuffer bytes) throws ReadOnlyBufferException, BufferOverflowException 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.- 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
RetainableByteBuffer.Mutable add(RetainableByteBuffer bytes) throws ReadOnlyBufferException, BufferOverflowException 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 similarappend(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 thanappend(RetainableByteBuffer)
if they already have an obligation to release the buffer and wish to delegate that obligation to this buffer.- 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
-
append
Copies the contents of the given byte buffer to the end of this buffer, growing this buffer if necessary and possible.- 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
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 similaradd(RetainableByteBuffer)
, implementations of this method mustRetainable.retain()
the passed buffer if they keep a reference to it.- 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:
-
put
Put abyte
to the buffer, growing this buffer if necessary and possible.- Parameters:
b
- thebyte
to put- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read only.BufferOverflowException
- if this buffer cannot fit the byte
-
putShort
Put ashort
to the buffer, growing this buffer if necessary and possible.- Parameters:
s
- theshort
to put- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read only.BufferOverflowException
- if this buffer cannot fit the byte
-
putInt
Put anint
to the buffer, growing this buffer if necessary and possible.- Parameters:
i
- theint
to put- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read onlyBufferOverflowException
- if this buffer cannot fit the byte
-
putLong
Put along
to the buffer, growing this buffer if necessary and possible.- Parameters:
l
- thelong
to put- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read onlyBufferOverflowException
- if this buffer cannot fit the byte
-
put
Put abyte
array to the buffer, growing this buffer if necessary and possible.- Parameters:
bytes
- thebyte
array to putoffset
- the offset into the arraylength
- the length in bytes to put- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read onlyBufferOverflowException
- if this buffer cannot fit the byte
-
put
Put abyte
array to the buffer, growing this buffer if necessary and possible.- Parameters:
bytes
- thebyte
array to put- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read onlyBufferOverflowException
- if this buffer cannot fit the byte
-
put
Put abyte
to the buffer at a given index.- Parameters:
index
- The index relative to the current start of unconsumed data in the buffer.b
- thebyte
to put- Returns:
this
buffer.- Throws:
ReadOnlyBufferException
- if this buffer is read only.BufferOverflowException
- if this buffer cannot fit the byte
-