public class HttpContent extends Object implements Callback, Closeable
HttpContent
is a stateful, linear representation of the request content provided
by a ContentProvider
that can be traversed one-way to obtain content buffers to
send to a HTTP server.
HttpContent
offers the notion of a one-way cursor to traverse the content.
The cursor starts in a virtual "before" position and can be advanced using advance()
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,
HttpContent
provides the following state:
getByteBuffer()
getContent()
isLast()
HttpContent
may not have content, if the related ContentProvider
is null
, and this
is reflected by hasContent()
.
HttpContent
may have deferred content
, in which case advance()
moves the cursor to a position that provides null
buffer
and
content
. When the deferred content is available, a further call to advance()
will move the cursor to a position that provides non null
buffer and content.Callback.Adapter
Constructor and Description |
---|
HttpContent(ContentProvider provider) |
Modifier and Type | Method and Description |
---|---|
boolean |
advance()
Advances the cursor to the next block of content.
|
void |
close() |
void |
failed(Throwable x)
Callback invoked when the operation fails.
|
ByteBuffer |
getByteBuffer() |
ByteBuffer |
getContent() |
boolean |
hasContent() |
boolean |
isConsumed() |
boolean |
isLast() |
void |
succeeded()
Callback invoked when the operation completes.
|
String |
toString() |
public HttpContent(ContentProvider provider)
public boolean hasContent()
public boolean isLast()
public ByteBuffer getByteBuffer()
ByteBuffer
containing the content at the cursor's positionpublic ByteBuffer getContent()
ByteBuffer.slice()
of getByteBuffer()
at the cursor's positionpublic boolean advance()
getByteBuffer()
), but may also be deferred
(which yields a null buffer returned by getByteBuffer()
).
If the block of content pointed by the new cursor position is valid, this method returns true.public boolean isConsumed()
last
position.public void succeeded()
Callback
Callback invoked when the operation completes.
succeeded
in interface Callback
Callback.failed(Throwable)
public void failed(Throwable x)
Callback
Callback invoked when the operation fails.
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 1995-2015 Webtide. All Rights Reserved.