- java.lang.Object
-
- org.eclipse.jetty.client.HttpContent
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,org.eclipse.jetty.util.Callback,org.eclipse.jetty.util.thread.Invocable
public class HttpContent extends java.lang.Object implements org.eclipse.jetty.util.Callback, java.io.CloseableHttpContentis 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.
-
-
Constructor Summary
Constructors Constructor Description HttpContent(ContentProvider provider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadvance()Advances the cursor to the next block of content.voidclose()voidfailed(java.lang.Throwable x)java.nio.ByteBuffergetByteBuffer()java.nio.ByteBuffergetContent()booleanhasContent()booleanisConsumed()booleanisLast()voidsucceeded()java.lang.StringtoString()
-
-
-
Constructor Detail
-
HttpContent
public HttpContent(ContentProvider provider)
-
-
Method Detail
-
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.
-
isConsumed
public boolean isConsumed()
- Returns:
- whether the cursor has been advanced past the
lastposition.
-
succeeded
public void succeeded()
- Specified by:
succeededin interfaceorg.eclipse.jetty.util.Callback
-
failed
public void failed(java.lang.Throwable x)
- Specified by:
failedin interfaceorg.eclipse.jetty.util.Callback
-
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
-
-