BidirectionalStream
public
abstract
class
BidirectionalStream
extends Object
java.lang.Object | |
↳ | android.net.http.BidirectionalStream |
Class for bidirectional sending and receiving of data over HTTP/2 or QUIC connections. Created by
Builder
.
Note: There are ordering restrictions on methods of BidirectionalStream
;
please see individual methods for description of restrictions.
Summary
Nested classes | |
---|---|
class |
BidirectionalStream.Builder
Builder for |
interface |
BidirectionalStream.Callback
Callback interface used to receive callbacks from a |
Constants | |
---|---|
int |
STREAM_PRIORITY_HIGHEST
Highest stream priority. |
int |
STREAM_PRIORITY_IDLE
Lowest stream priority. |
int |
STREAM_PRIORITY_LOW
Low stream priority. |
int |
STREAM_PRIORITY_LOWEST
Very low stream priority. |
int |
STREAM_PRIORITY_MEDIUM
Medium stream priority. |
Public constructors | |
---|---|
BidirectionalStream()
|
Public methods | |
---|---|
abstract
void
|
cancel()
Cancels the stream. |
abstract
void
|
flush()
Flushes pending writes. |
abstract
HeaderBlock
|
getHeaders()
|
abstract
String
|
getHttpMethod()
|
abstract
int
|
getPriority()
|
abstract
int
|
getTrafficStatsTag()
|
abstract
int
|
getTrafficStatsUid()
|
abstract
boolean
|
hasTrafficStatsTag()
|
abstract
boolean
|
hasTrafficStatsUid()
|
abstract
boolean
|
isDelayRequestHeadersUntilFirstFlushEnabled()
See |
abstract
boolean
|
isDone()
Returns |
abstract
void
|
read(ByteBuffer buffer)
Reads data from the stream into the provided buffer. |
abstract
void
|
start()
Starts the stream, all callbacks go to the |
abstract
void
|
write(ByteBuffer buffer, boolean endOfStream)
Attempts to write data from the provided buffer into the stream. |
Inherited methods | |
---|---|
Constants
STREAM_PRIORITY_HIGHEST
public static final int STREAM_PRIORITY_HIGHEST
Highest stream priority. Passed to Builder#setPriority
.
Constant Value: 4 (0x00000004)
STREAM_PRIORITY_IDLE
public static final int STREAM_PRIORITY_IDLE
Lowest stream priority. Passed to Builder#setPriority
.
Constant Value: 0 (0x00000000)
STREAM_PRIORITY_LOW
public static final int STREAM_PRIORITY_LOW
Low stream priority. Passed to Builder#setPriority
.
Constant Value: 2 (0x00000002)
STREAM_PRIORITY_LOWEST
public static final int STREAM_PRIORITY_LOWEST
Very low stream priority. Passed to Builder#setPriority
.
Constant Value: 1 (0x00000001)
STREAM_PRIORITY_MEDIUM
public static final int STREAM_PRIORITY_MEDIUM
Medium stream priority. Passed to Builder#setPriority
. This is the
default priority given to the stream.
Constant Value: 3 (0x00000003)
Public constructors
Public methods
cancel
public abstract void cancel ()
Cancels the stream. Can be called at any time after start()
. onCanceled()
will be invoked when cancelation is complete and no further
callback methods will be invoked. If the stream has completed or has not started, calling
cancel()
has no effect and onCanceled()
will not be invoked. If the Executor
passed in during
BidirectionalStream
construction runs tasks on a single thread, and cancel()
is called on that thread, no listener methods (besides onCanceled()
) will be invoked
after
cancel()
is called. Otherwise, at most one callback method may be invoked after
cancel()
has completed.
flush
public abstract void flush ()
Flushes pending writes. This method should not be invoked before onStreamReady()
. For previously delayed write()
s, a
corresponding onWriteCompleted()
will be invoked when the
buffer is sent.
getHeaders
public abstract HeaderBlock getHeaders ()
See Builder#addHeader(String, String)
Returns | |
---|---|
HeaderBlock |
This value cannot be null . |
getHttpMethod
public abstract String getHttpMethod ()
See BidirectionalStream.Builder#setHttpMethod(String)
.
Returns | |
---|---|
String |
This value cannot be null . |
getPriority
public abstract int getPriority ()
Returns | |
---|---|
int |
Value is STREAM_PRIORITY_IDLE , STREAM_PRIORITY_LOWEST , STREAM_PRIORITY_LOW , STREAM_PRIORITY_MEDIUM , or STREAM_PRIORITY_HIGHEST |
getTrafficStatsTag
public abstract int getTrafficStatsTag ()
See BidirectionalStream.Builder#setTrafficStatsTag(int)
Returns | |
---|---|
int |
getTrafficStatsUid
public abstract int getTrafficStatsUid ()
See BidirectionalStream.Builder#setTrafficStatsUid(int)
Returns | |
---|---|
int |
hasTrafficStatsTag
public abstract boolean hasTrafficStatsTag ()
See BidirectionalStream.Builder#setTrafficStatsTag(int)
Returns | |
---|---|
boolean |
hasTrafficStatsUid
public abstract boolean hasTrafficStatsUid ()
See BidirectionalStream.Builder#setTrafficStatsUid(int)
Returns | |
---|---|
boolean |
isDelayRequestHeadersUntilFirstFlushEnabled
public abstract boolean isDelayRequestHeadersUntilFirstFlushEnabled ()
See Builder#setDelayRequestHeadersUntilFirstFlushEnabled(boolean)
Returns | |
---|---|
boolean |
isDone
public abstract boolean isDone ()
Returns true
if the stream was successfully started and is now done (succeeded,
canceled, or failed).
Returns | |
---|---|
boolean |
true if the stream was successfully started and is now done (completed,
canceled, or failed), otherwise returns false to indicate stream is not yet started
or is in progress. |
read
public abstract void read (ByteBuffer buffer)
Reads data from the stream into the provided buffer. Can only be called at most once in
response to each invocation of the onStreamReady()
/ onResponseHeadersReceived()
and onReadCompleted()
methods of the Callback
. Each call will
result in an invocation of one of the Callback
's onReadCompleted()
method if data is read, or its onFailed()
method if there's an error.
An attempt to read data into buffer
starting at buffer.position()
is begun.
At most buffer.remaining()
bytes are read. buffer.position()
is updated upon
invocation of onReadCompleted()
to indicate how much data
was read.
Parameters | |
---|---|
buffer |
ByteBuffer : the ByteBuffer to read data into. Must be a direct ByteBuffer. The
embedder must not read or modify buffer's position, limit, or data between its position and
limit until onReadCompleted() , onCanceled() , or onFailed() are invoked.
This value cannot be null . |
start
public abstract void start ()
Starts the stream, all callbacks go to the callback
argument passed to BidirectionalStream.Builder
's constructor. Should only be called once.
write
public abstract void write (ByteBuffer buffer, boolean endOfStream)
Attempts to write data from the provided buffer into the stream. If auto flush is disabled,
data will be sent only after flush()
is called. Each call will result in an
invocation of one of the Callback
's onWriteCompleted()
method if data is sent, or its onFailed()
method if there's an error.
An attempt to write data from buffer
starting at buffer.position()
is begun.
buffer.remaining()
bytes will be written. onWriteCompleted()
will be invoked only when the full ByteBuffer is written.
Parameters | |
---|---|
buffer |
ByteBuffer : the ByteBuffer to write data from. Must be a direct ByteBuffer. The
embedder must not read or modify buffer's position, limit, or data between its position and
limit until onWriteCompleted() , onCanceled() , or onFailed() are invoked. Can be empty when endOfStream is true .
This value cannot be null . |
endOfStream |
boolean : if true , then buffer is the last buffer to be written, and
once written, stream is closed from the client side, resulting in half-closed stream or a
fully closed stream if the remote side has already closed. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.