- All Superinterfaces:
Retainable
- All Known Implementing Classes:
Content.Chunk.Error
- 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 final classA chunk that wraps a failure.static interfaceImplementations of this interface may processContent.Chunks being copied by theContent.copy(Source, Sink, Processor, Callback)method, so thatContent.Chunks of unknown types can be copied.Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Retainable
Retainable.ReferenceCounter, Retainable.Wrapper -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Content.ChunkAn empty, non-last, chunk.static final Content.ChunkAn empty, last, chunk. -
Method Summary
Modifier and TypeMethodDescriptionstatic Content.ChunkasChunk(ByteBuffer byteBuffer, boolean last, Retainable retainable) static Content.Chunk.ErrorCreates anerror chunkwith the given failure.static Content.Chunkfrom(ByteBuffer byteBuffer, boolean last) Creates a Chunk with the given ByteBuffer.static Content.Chunkfrom(ByteBuffer byteBuffer, boolean last, Runnable releaser) Creates a Chunk with the given ByteBuffer.static Content.Chunkfrom(ByteBuffer byteBuffer, boolean last, Consumer<ByteBuffer> releaser) Creates a last/non-last Chunk with the given ByteBuffer.default intget(byte[] bytes, int offset, int length) Copies the bytes from this Chunk to the given byte array.default booleanbooleanisLast()static Content.Chunknext(Content.Chunk chunk) Returns the chunk that follows the given chunk.default intdefault intskip(int length) Skips, advancing the ByteBuffer position, the given number of bytes.Methods inherited from interface org.eclipse.jetty.io.Retainable
canRetain, release, retain
-
Field Details
-
EMPTY
An empty, non-last, chunk.
-
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
ByteBufferandlastarguments as aChunk, linked to the givenRetainable.The
Retainable.retain()andRetainable.release()methods of thisChunkwill 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
- Throws:
IllegalArgumentException- if theRetainablecannot be retained
-
from
Creates an
error chunkwith the given failure.- Parameters:
failure- the cause of the failure- Returns:
- a new Error.Chunk
-
next
-
getByteBuffer
ByteBuffer getByteBuffer()- Returns:
- the ByteBuffer of this Chunk
-
isLast
boolean isLast()- Returns:
- whether this is the last Chunk
-
remaining
default int remaining()- Returns:
- the number of bytes remaining in this Chunk
-
hasRemaining
default boolean hasRemaining()- Returns:
- whether this Chunk has remaining bytes
-
get
default int get(byte[] bytes, int offset, int length) Copies the bytes from this Chunk to the given byte array.
- 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
-
skip
default int skip(int length) Skips, advancing the ByteBuffer position, the given number of bytes.
- Parameters:
length- the maximum number of bytes to skip- Returns:
- the number of bytes actually skipped
-