Class RetainableByteBuffer.FixedCapacity
java.lang.Object
org.eclipse.jetty.io.Retainable.Wrapper
org.eclipse.jetty.io.RetainableByteBuffer.Abstract
org.eclipse.jetty.io.RetainableByteBuffer.FixedCapacity
- All Implemented Interfaces:
Retainable
,RetainableByteBuffer
,RetainableByteBuffer.Mutable
- Direct Known Subclasses:
AbstractRetainableByteBuffer
,ArrayByteBufferPool.Tracking.TrackedBuffer
,RetainableByteBuffer.NonRetainableByteBuffer
,RetainableByteBuffer.Pooled
- Enclosing interface:
RetainableByteBuffer
public static class RetainableByteBuffer.FixedCapacity
extends RetainableByteBuffer.Abstract
implements RetainableByteBuffer.Mutable
-
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
ConstructorsConstructorDescriptionFixedCapacity
(ByteBuffer byteBuffer) FixedCapacity
(ByteBuffer byteBuffer, Retainable retainable) -
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.protected void
addValueMarker
(StringBuilder builder, boolean beginning) 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.Access this buffer via theRetainableByteBuffer.Mutable
API.int
capacity()
void
clear()
byte
get
(long index) Returns a byte from this RetainableByteBuffer at a specific indexGet the wrapped, notnull
,ByteBuffer
.boolean
boolean
isDirect()
void
limit
(long size) Limit this buffer's contents to the size.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.int
long
space()
Methods inherited from class org.eclipse.jetty.io.RetainableByteBuffer.Abstract
addExtraStringInfo, addStringInfo, addValueString, toDetailString, toString
Methods inherited from class org.eclipse.jetty.io.Retainable.Wrapper
canRetain, getRetained, getWrapped, isRetained, 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, isRetained, release, retain
Methods inherited from interface org.eclipse.jetty.io.RetainableByteBuffer
appendTo, appendTo, copy, get, get, isEmpty, isFull, isMutable, maxSize, putTo, size, skip, slice, slice, take, take, takeByteArray, takeFrom, toDetailString, writeTo, writeTo
Methods inherited from interface org.eclipse.jetty.io.RetainableByteBuffer.Mutable
put
-
Constructor Details
-
FixedCapacity
-
FixedCapacity
-
-
Method Details
-
clear
public void clear()- Specified by:
clear
in interfaceRetainableByteBuffer
- See Also:
-
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
.
-
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:
-
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
-
isDirect
public boolean isDirect()- Specified by:
isDirect
in interfaceRetainableByteBuffer
- Returns:
- whether the
ByteBuffer
is direct
-
capacity
public int capacity()- Specified by:
capacity
in interfaceRetainableByteBuffer
- Returns:
- the capacity
- See Also:
-
get
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
- Throws:
IndexOutOfBoundsException
- if the index is too large.
-
limit
public void limit(long size) Description copied from interface:RetainableByteBuffer
Limit this buffer's contents to the size.
- Specified by:
limit
in interfaceRetainableByteBuffer
- Parameters:
size
- the new size of the buffer
-
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
-
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
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.- See Also:
-
add
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.
-
put
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.- 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 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
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.- 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.- Specified by:
putInt
in interfaceRetainableByteBuffer.Mutable
- 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.- Specified by:
putLong
in interfaceRetainableByteBuffer.Mutable
- 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.- 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.- Throws:
ReadOnlyBufferException
- if this buffer is read onlyBufferOverflowException
- if this buffer cannot fit the byte
-
addValueMarker
- Overrides:
addValueMarker
in classRetainableByteBuffer.Abstract
-