Class HttpContent
- java.lang.Object
-
- org.eclipse.jetty.client.HttpContent
-
public class HttpContent extends java.lang.Object implements Callback, java.io.Closeable
HttpContentis a stateful, linear representation of the request content provided by aContentProviderthat can be traversed one-way to obtain content buffers to send to an HTTP server.HttpContentoffers the notion of a one-way cursor to traverse the content. The cursor starts in a virtual "before" position and can be advanced usingadvance()until it reaches a virtual "after" position where the content is fully consumed.+---+ +---+ +---+ +---+ +---+ | | | | | | | | | | +---+ +---+ +---+ +---+ +---+ ^ ^ ^ ^ | | --> advance() | | | | last | | | | before | after | currentAt each valid (non-before and non-after) cursor position,HttpContentprovides the following state:- the buffer containing the content to send, via
getByteBuffer() - a copy of the content buffer that can be used for notifications, via
getContent() - whether the buffer to write is the last one, via
isLast()
HttpContentmay not have content, if the relatedContentProviderisnull, and this is reflected byhasContent().HttpContentmay havedeferred content, in which caseadvance()moves the cursor to a position that providesnullbufferandcontent. When the deferred content is available, a further call toadvance()will move the cursor to a position that provides nonnullbuffer and content. - the buffer containing the content to send, via
-
-
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
-
-
Field Summary
Fields Modifier and Type Field Description private static java.nio.ByteBufferAFTERprivate java.nio.ByteBufferbufferprivate static java.nio.ByteBufferCLOSEprivate java.nio.ByteBuffercontentprivate java.util.Iterator<java.nio.ByteBuffer>iteratorprivate booleanlastprivate static LoggerLOGprivate ContentProviderprovider-
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
-
Constructor Summary
Constructors Constructor Description HttpContent(ContentProvider provider)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadvance()Advances the cursor to the next block of content.private booleanadvance(java.util.Iterator<java.nio.ByteBuffer> iterator)voidclose()voidfailed(java.lang.Throwable x)Callback invoked when the operation fails.java.nio.ByteBuffergetByteBuffer()java.nio.ByteBuffergetContent()booleanhasContent()booleanisConsumed()booleanisLast()private static booleanisTheCloseBuffer(java.nio.ByteBuffer buffer)voidsucceeded()Callback invoked when the operation completes.java.lang.StringtoString()-
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.thread.Invocable
getInvocationType
-
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
AFTER
private static final java.nio.ByteBuffer AFTER
-
CLOSE
private static final java.nio.ByteBuffer CLOSE
-
provider
private final ContentProvider provider
-
iterator
private final java.util.Iterator<java.nio.ByteBuffer> iterator
-
buffer
private java.nio.ByteBuffer buffer
-
content
private java.nio.ByteBuffer content
-
last
private boolean last
-
-
Constructor Detail
-
HttpContent
public HttpContent(ContentProvider provider)
-
-
Method Detail
-
isTheCloseBuffer
private static boolean isTheCloseBuffer(java.nio.ByteBuffer buffer)
- Returns:
- true if the buffer is the sentinel instance
CLOSE
-
hasContent
public boolean hasContent()
- Returns:
- whether there is any content at all
-
isLast
public boolean isLast()
- Returns:
- whether the cursor points to the last content
-
getByteBuffer
public java.nio.ByteBuffer getByteBuffer()
- Returns:
- the
ByteBuffercontaining the content at the cursor's position
-
getContent
public java.nio.ByteBuffer getContent()
- Returns:
- a
ByteBuffer.slice()ofgetByteBuffer()at the cursor's position
-
advance
public boolean advance()
Advances the cursor to the next block of content.The next block of content may be valid (which yields a non-null buffer returned by
getByteBuffer()), but may also be deferred (which yields a null buffer returned bygetByteBuffer()).If the block of content pointed by the new cursor position is valid, this method returns true.
- Returns:
- true if there is content at the new cursor's position, false otherwise.
-
advance
private boolean advance(java.util.Iterator<java.nio.ByteBuffer> iterator)
-
isConsumed
public boolean isConsumed()
- Returns:
- whether the cursor has been advanced past the
lastposition.
-
succeeded
public void succeeded()
Description copied from interface:CallbackCallback invoked when the operation completes.
- Specified by:
succeededin interfaceCallback- See Also:
Callback.failed(Throwable)
-
failed
public void failed(java.lang.Throwable x)
Description copied from interface:CallbackCallback invoked when the operation fails.
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-