Interface Content.Chunk
- All Superinterfaces:
Retainable
,RetainableByteBuffer
- All Known Implementing Classes:
Content.Chunk.Empty
,Trailers
- Enclosing class:
Content
A chunk of content indicating whether it is the last chunk.
Optionally, a release function may be specified (for example
to release the ByteBuffer
back into a pool), or the
Retainable.release()
method overridden.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
An empty chunk implementation.static interface
Implementations of this interface may processContent.Chunk
s being copied by theContent.copy(Source, Sink, Processor, Callback)
method, so thatContent.Chunk
s of unknown types can be copied.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
FieldsModifier and TypeFieldDescriptionstatic final Content.Chunk
An empty, non-last, chunk instance.static final Content.Chunk
An empty, last, chunk.Fields inherited from interface org.eclipse.jetty.io.Retainable
NON_RETAINABLE
-
Method Summary
Modifier and TypeMethodDescriptionstatic Content.Chunk
asChunk
(ByteBuffer byteBuffer, boolean last, Retainable retainable) default Content.Chunk
Deprecated, for removal: This API element is subject to removal in a future version.static Content.Chunk
Creates anfailure chunk
with the given failure andisLast()
returning true.static Content.Chunk
Creates anfailure chunk
with the given failure and givenlast
state.static Content.Chunk
from
(ByteBuffer byteBuffer, boolean last) Creates a Chunk with the given ByteBuffer.static Content.Chunk
from
(ByteBuffer byteBuffer, boolean last, Runnable releaser) Creates a Chunk with the given ByteBuffer.static Content.Chunk
from
(ByteBuffer byteBuffer, boolean last, Consumer<ByteBuffer> releaser) Creates a last/non-last Chunk with the given ByteBuffer.default Throwable
static boolean
isFailure
(Content.Chunk chunk) static boolean
isFailure
(Content.Chunk chunk, boolean last) boolean
isLast()
static Content.Chunk
next
(Content.Chunk chunk) Returns the chunk that follows the given chunk.static Content.Chunk
releaseAndNext
(Content.Chunk chunk) Convenience method to release a chunk and returnnext(Chunk)
.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
-
Field Details
-
EMPTY
An empty, non-last, chunk instance.
-
EOF
An empty, last, chunk.
-
-
Method Details
-
from
Creates a Chunk with the given ByteBuffer.
The returned Chunk must be
released
.- Parameters:
byteBuffer
- the ByteBuffer with the bytes of this Chunklast
- whether the Chunk is the last one- Returns:
- a new Chunk
-
from
Creates a Chunk with the given ByteBuffer.
The returned Chunk must be
released
.- Parameters:
byteBuffer
- the ByteBuffer with the bytes of this Chunklast
- whether the Chunk is the last onereleaser
- the code to run when this Chunk is released- Returns:
- a new Chunk
-
from
Creates a last/non-last Chunk with the given ByteBuffer.
The returned Chunk must be
released
.- Parameters:
byteBuffer
- the ByteBuffer with the bytes of this Chunklast
- whether the Chunk is the last onereleaser
- the code to run when this Chunk is released- Returns:
- a new Chunk
-
asChunk
Returns the given
ByteBuffer
andlast
arguments as aChunk
, linked to the givenRetainable
.The
Retainable.retain()
andRetainable.release()
methods of thisChunk
will delegate to the givenRetainable
.- Parameters:
byteBuffer
- the ByteBuffer with the bytes of this Chunklast
- whether the Chunk is the last oneretainable
- the Retainable this Chunk links to- Returns:
- a new Chunk
-
from
Creates an
failure chunk
with the given failure andisLast()
returning true.- Parameters:
failure
- the cause of the failure- Returns:
- a new
failure chunk
-
from
Creates an
failure chunk
with the given failure and givenlast
state.- Parameters:
failure
- the cause of the failurelast
- true if the failure is terminal, else false for transient failure- Returns:
- a new
failure chunk
-
next
-
releaseAndNext
Convenience method to release a chunk and returnnext(Chunk)
. Equivalent to:if (chunk != null) { chunk.release(); chunk = Chunk.next(chunk); }
- Parameters:
chunk
- The chunk to release ornull
- Returns:
- The
next(Chunk)
chunk;
-
isFailure
- Parameters:
chunk
- The chunk to test for anfailure
.- Returns:
- True if the chunk is non-null and
chunk.getError()
returns non-null.
-
isFailure
- Parameters:
chunk
- The chunk to test for anfailure
last
- Thelast
status to test for.- Returns:
- True if the chunk is non-null and
getFailure()
returns non-null andisLast()
matches the passed status.
-
getFailure
Get a failure (which may be from afailure
or awarning
), if any, associated with the chunk.- A
chunk
must not have a failure and aRetainableByteBuffer.getByteBuffer()
with content. - A
chunk
with a failure may or may not belast
. - A
chunk
with a failure must not beretainable
.
- Returns:
- A
Throwable
indicating the failure or null if there is no failure or warning. - See Also:
- A
-
isLast
boolean isLast()- Returns:
- whether this is the last Chunk
-
asReadOnly
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- an immutable version of this Chunk
-