- java.lang.Object
-
- org.eclipse.jetty.server.HttpInput.Content
-
- All Implemented Interfaces:
org.eclipse.jetty.util.Callback,org.eclipse.jetty.util.thread.Invocable
- Direct Known Subclasses:
HttpInput.SpecialContent,HttpInput.WrappingContent
- Enclosing class:
- HttpInput
public static class HttpInput.Content extends java.lang.Object implements org.eclipse.jetty.util.CallbackA content represents the production of aHttpChannelreturned byHttpChannel.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 viaCallback.succeeded()orCallback.failed(Throwable). Special content indicates a special event, like EOF or an error and never wraps a byte buffer. CallingCallback.succeeded()orCallback.failed(Throwable)on those have no effect.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.ByteBuffer_content
-
Constructor Summary
Constructors Constructor Description Content(java.nio.ByteBuffer content)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intget(byte[] buffer, int offset, int length)Read the wrapped byte buffer.java.nio.ByteBuffergetByteBuffer()Get the wrapped byte buffer.java.lang.ThrowablegetError()Get the reported error.org.eclipse.jetty.util.thread.Invocable.InvocationTypegetInvocationType()booleanhasContent()Check if there is at least one byte left in the buffer.booleanisEmpty()Check if the buffer is empty.booleanisEof()Check if EOF was reached.booleanisSpecial()Check if the content is special.intremaining()Get the number of bytes remaining in the buffer.intskip(int length)Skip some bytes from the buffer.java.lang.StringtoString()
-
-
-
Method Detail
-
getByteBuffer
public java.nio.ByteBuffer getByteBuffer()
Get the wrapped byte buffer. ThrowsIllegalStateExceptionif the content is special.- Returns:
- the wrapped byte buffer.
-
getInvocationType
public org.eclipse.jetty.util.thread.Invocable.InvocationType getInvocationType()
- Specified by:
getInvocationTypein interfaceorg.eclipse.jetty.util.thread.Invocable
-
get
public int get(byte[] buffer, int offset, int length)Read the wrapped byte buffer. ThrowsIllegalStateExceptionif 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
public java.lang.Throwable getError()
Get the reported error. Only special contents can have an error.- Returns:
- the error or null if there is none.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-