Package org.eclipse.jetty.server
Class HttpInput.Content
java.lang.Object
org.eclipse.jetty.server.HttpInput.Content
- Direct Known Subclasses:
HttpInput.SpecialContent
,HttpInput.WrappingContent
- Enclosing class:
- HttpInput
A content represents the production of a
HttpChannel
returned by HttpChannel.produceContent()
.
There are two fundamental types of content: special and non-special.
Non-special content always wraps a byte buffer that can be consumed and must be recycled once it is empty, either
via Callback.succeeded()
or Callback.failed(Throwable)
.
Special content indicates a special event, like EOF or an error and never wraps a byte buffer. Calling
Callback.succeeded()
or Callback.failed(Throwable)
on those have no effect.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback
Callback.Completable, Callback.Completing, Callback.Nested
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task
-
Field Summary
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
get
(byte[] buffer, int offset, int length) Read the wrapped byte buffer.Get the wrapped byte buffer.getError()
Get the reported error.boolean
Check if there is at least one byte left in the buffer.boolean
isEmpty()
Check if the buffer is empty.boolean
isEof()
Check if EOF was reached.boolean
Check if the content is special.int
Get the number of bytes remaining in the buffer.int
skip
(int length) Skip some bytes from the buffer.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.Callback
completeWith, failed, succeeded
-
Field Details
-
_content
-
-
Constructor Details
-
Content
-
-
Method Details
-
getByteBuffer
Get the wrapped byte buffer. ThrowsIllegalStateException
if the content is special.- Returns:
- the wrapped byte buffer.
-
getInvocationType
- Specified by:
getInvocationType
in interfaceInvocable
- Returns:
- The InvocationType of this object
-
get
public int get(byte[] buffer, int offset, int length) Read the wrapped byte buffer. ThrowsIllegalStateException
if the content is special.- Parameters:
buffer
- The array into which bytes are to be written.offset
- The offset within the array of the first byte to be written.length
- The maximum number of bytes to be written to the given array.- Returns:
- The amount of bytes read from the buffer.
-
skip
public int skip(int length) Skip some bytes from the buffer. Has no effect on a special content.- Parameters:
length
- How many bytes to skip.- Returns:
- How many bytes were skipped.
-
hasContent
public boolean hasContent()Check if there is at least one byte left in the buffer. Always false on a special content.- Returns:
- true if there is at least one byte left in the buffer.
-
remaining
public int remaining()Get the number of bytes remaining in the buffer. Always 0 on a special content.- Returns:
- the number of bytes remaining in the buffer.
-
isEmpty
public boolean isEmpty()Check if the buffer is empty. Always true on a special content.- Returns:
- true if there is 0 byte left in the buffer.
-
isSpecial
public boolean isSpecial()Check if the content is special. A content is deemed special if it does not hold bytes but rather conveys a special event, like when EOF has been reached or an error has occurred.- Returns:
- true if the content is special, false otherwise.
-
isEof
public boolean isEof()Check if EOF was reached. Both special and non-special content can have this flag set to true but in the case of non-special content, this can be interpreted as a hint as it is always going to be followed by another content that is both special and EOF.- Returns:
- true if EOF was reached, false otherwise.
-
getError
Get the reported error. Only special contents can have an error.- Returns:
- the error or null if there is none.
-
toString
-