public final class Http2Stream
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) class |
Http2Stream.FramingSink
A sink that writes outgoing data frames of a stream.
|
private class |
Http2Stream.FramingSource
A source that reads the incoming data frames of a stream.
|
(package private) class |
Http2Stream.StreamTimeout
The Okio timeout watchdog will call
Http2Stream.StreamTimeout.timedOut() if the timeout is reached. |
Modifier and Type | Field and Description |
---|---|
(package private) long |
bytesLeftInWriteWindow
Count of bytes that can be written on the stream before receiving a window update.
|
(package private) Http2Connection |
connection |
(package private) ErrorCode |
errorCode
The reason why this stream was abnormally closed.
|
(package private) java.io.IOException |
errorException
The exception that explains
errorCode . |
private boolean |
hasResponseHeaders
True if response headers have been sent or received.
|
private java.util.Deque<Headers> |
headersQueue
|
(package private) int |
id |
(package private) Http2Stream.StreamTimeout |
readTimeout |
(package private) Http2Stream.FramingSink |
sink |
private Http2Stream.FramingSource |
source |
(package private) long |
unacknowledgedBytesRead
The total number of bytes consumed by the application (with
Http2Stream.FramingSource.read(okio.Buffer, long) ), but
not yet acknowledged by sending a WINDOW_UPDATE frame on this stream. |
(package private) Http2Stream.StreamTimeout |
writeTimeout |
Constructor and Description |
---|
Http2Stream(int id,
Http2Connection connection,
boolean outFinished,
boolean inFinished,
Headers headers) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
addBytesToWriteWindow(long delta)
delta will be negative if a settings frame initial window is smaller than the last. |
(package private) void |
cancelStreamIfNecessary() |
(package private) void |
checkOutNotClosed() |
void |
close(ErrorCode rstStatusCode,
java.io.IOException errorException)
Abnormally terminate this stream.
|
private boolean |
closeInternal(ErrorCode errorCode,
java.io.IOException errorException)
Returns true if this stream was closed.
|
void |
closeLater(ErrorCode errorCode)
Abnormally terminate this stream.
|
void |
enqueueTrailers(Headers trailers) |
Http2Connection |
getConnection() |
ErrorCode |
getErrorCode()
Returns the reason why this stream was closed, or null if it closed normally or has not yet
been closed.
|
int |
getId() |
okio.Sink |
getSink()
Returns a sink that can be used to write data to the peer.
|
okio.Source |
getSource()
Returns a source that reads data from the peer.
|
boolean |
isLocallyInitiated()
Returns true if this stream was created by this peer.
|
boolean |
isOpen()
Returns true if this stream is open.
|
okio.Timeout |
readTimeout() |
(package private) void |
receiveData(okio.BufferedSource in,
int length) |
(package private) void |
receiveHeaders(Headers headers,
boolean inFinished)
Accept headers from the network and store them until the client calls
takeHeaders() , or
Http2Stream.FramingSource.read(okio.Buffer, long) them. |
(package private) void |
receiveRstStream(ErrorCode errorCode) |
Headers |
takeHeaders()
Removes and returns the stream's received response headers, blocking if necessary until headers
have been received.
|
Headers |
trailers()
Returns the trailers.
|
(package private) void |
waitForIo()
Like
Object.wait(long) , but throws an InterruptedIOException when interrupted instead of
the more awkward InterruptedException . |
void |
writeHeaders(java.util.List<Header> responseHeaders,
boolean outFinished,
boolean flushHeaders)
Sends a reply to an incoming stream.
|
okio.Timeout |
writeTimeout() |
long unacknowledgedBytesRead
Http2Stream.FramingSource.read(okio.Buffer, long)
), but
not yet acknowledged by sending a WINDOW_UPDATE
frame on this stream.long bytesLeftInWriteWindow
connection.bytesLeftInWriteWindow
.final int id
final Http2Connection connection
private final java.util.Deque<Headers> headersQueue
private boolean hasResponseHeaders
private final Http2Stream.FramingSource source
final Http2Stream.FramingSink sink
final Http2Stream.StreamTimeout readTimeout
final Http2Stream.StreamTimeout writeTimeout
@Nullable ErrorCode errorCode
@Nullable java.io.IOException errorException
errorCode
. Null if no exception was provided.Http2Stream(int id, Http2Connection connection, boolean outFinished, boolean inFinished, @Nullable Headers headers)
public int getId()
public boolean isOpen()
SYN_RESET
frame abnormally terminates the stream.
Note that the input stream may continue to yield data even after a stream reports itself as not open. This is because input data is buffered.
public boolean isLocallyInitiated()
public Http2Connection getConnection()
public Headers takeHeaders() throws java.io.IOException
java.io.IOException
public Headers trailers() throws java.io.IOException
java.io.IOException
public ErrorCode getErrorCode()
public void writeHeaders(java.util.List<Header> responseHeaders, boolean outFinished, boolean flushHeaders) throws java.io.IOException
outFinished
- true to eagerly finish the output stream to send data to the remote peer.
Corresponds to FLAG_FIN
.flushHeaders
- true to force flush the response headers. This should be true unless the
response body exists and will be written immediately.java.io.IOException
public void enqueueTrailers(Headers trailers)
public okio.Timeout readTimeout()
public okio.Timeout writeTimeout()
public okio.Source getSource()
public okio.Sink getSink()
java.lang.IllegalStateException
- if this stream was initiated by the peer and a writeHeaders(java.util.List<okhttp3.internal.http2.Header>, boolean, boolean)
has not yet been sent.public void close(ErrorCode rstStatusCode, @Nullable java.io.IOException errorException) throws java.io.IOException
RST_STREAM
frame has been
transmitted.java.io.IOException
public void closeLater(ErrorCode errorCode)
RST_STREAM
frame and returns
immediately.private boolean closeInternal(ErrorCode errorCode, @Nullable java.io.IOException errorException)
void receiveData(okio.BufferedSource in, int length) throws java.io.IOException
java.io.IOException
void receiveHeaders(Headers headers, boolean inFinished)
takeHeaders()
, or
Http2Stream.FramingSource.read(okio.Buffer, long)
them.void receiveRstStream(ErrorCode errorCode)
void cancelStreamIfNecessary() throws java.io.IOException
java.io.IOException
void addBytesToWriteWindow(long delta)
delta
will be negative if a settings frame initial window is smaller than the last.void checkOutNotClosed() throws java.io.IOException
java.io.IOException
void waitForIo() throws java.io.InterruptedIOException
Object.wait(long)
, but throws an InterruptedIOException
when interrupted instead of
the more awkward InterruptedException
.java.io.InterruptedIOException