java.lang.Object
org.miaixz.bus.http.metric.http.Http2Stream
A logical bidirectional stream.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose(Http2ErrorCode rstStatusCode, IOException errorException) Abnormally terminate this stream.voidcloseLater(Http2ErrorCode errorCode) Abnormally terminate this stream.voidenqueueTrailers(Headers trailers) Enqueues trailers to be sent after the last data frame of this stream.Returns the connection that this stream is on.Returns the reason why this stream was closed, or null if it closed normally or has not yet been closed.intgetId()Returns the stream's ID.org.miaixz.bus.core.io.sink.SinkgetSink()Returns a sink that can be used to write data to the peer.org.miaixz.bus.core.io.source.SourceReturns a source that reads data from the peer.booleanReturns true if this stream was created by this peer.booleanisOpen()Returns true if this stream is open.org.miaixz.bus.core.io.timout.TimeoutReturns the timeout for reading from this stream.Removes and returns the stream's received response headers, blocking if necessary until headers have been received.trailers()Returns the trailers.voidwriteHeaders(List<Http2Header> responseHeaders, boolean outFinished, boolean flushHeaders) Sends a reply to an incoming stream.org.miaixz.bus.core.io.timout.TimeoutReturns the timeout for writing to this stream.
-
Method Details
-
getId
public int getId()Returns the stream's ID.- Returns:
- the stream's ID.
-
isOpen
public boolean isOpen()Returns true if this stream is open. A stream is open until either:- A
SYN_RESETframe abnormally terminates the stream. - Both input and output streams have transmitted all data and headers.
- Returns:
- true if this stream is open.
- A
-
isLocallyInitiated
public boolean isLocallyInitiated()Returns true if this stream was created by this peer.- Returns:
- true if this stream was created by this peer.
-
getConnection
Returns the connection that this stream is on.- Returns:
- the connection that this stream is on.
-
takeHeaders
Removes and returns the stream's received response headers, blocking if necessary until headers have been received. If the returned list contains multiple blocks of headers the blocks will be delimited by 'null'.- Returns:
- the stream's received response headers.
- Throws:
IOException- if an I/O error occurs.
-
trailers
Returns the trailers. It is only safe to call this once the source stream has been completely exhausted.- Returns:
- the trailers.
- Throws:
IOException- if an I/O error occurs.
-
getErrorCode
Returns the reason why this stream was closed, or null if it closed normally or has not yet been closed.- Returns:
- the reason why this stream was closed.
-
writeHeaders
public void writeHeaders(List<Http2Header> responseHeaders, boolean outFinished, boolean flushHeaders) throws IOException Sends a reply to an incoming stream.- Parameters:
responseHeaders- the response headers.outFinished- true to eagerly finish the output stream to send data to the remote peer. Corresponds toFLAG_FIN.flushHeaders- true to force flush the response headers. This should be true unless the response body exists and will be written immediately.- Throws:
IOException- if an I/O error occurs.
-
enqueueTrailers
Enqueues trailers to be sent after the last data frame of this stream.- Parameters:
trailers- the trailers to send.
-
readTimeout
public org.miaixz.bus.core.io.timout.Timeout readTimeout()Returns the timeout for reading from this stream.- Returns:
- the timeout for reading from this stream.
-
writeTimeout
public org.miaixz.bus.core.io.timout.Timeout writeTimeout()Returns the timeout for writing to this stream.- Returns:
- the timeout for writing to this stream.
-
getSource
public org.miaixz.bus.core.io.source.Source getSource()Returns a source that reads data from the peer.- Returns:
- a source that reads data from the peer.
-
getSink
public org.miaixz.bus.core.io.sink.Sink getSink()Returns a sink that can be used to write data to the peer.- Returns:
- a sink that can be used to write data to the peer.
- Throws:
IllegalStateException- if this stream was initiated by the peer and awriteHeaders(java.util.List<org.miaixz.bus.http.metric.http.Http2Header>, boolean, boolean)has not yet been sent.
-
close
Abnormally terminate this stream. This blocks until theRST_STREAMframe has been transmitted.- Parameters:
rstStatusCode- the reason for closing the stream.errorException- the exception that caused the closure.- Throws:
IOException- if an I/O error occurs.
-
closeLater
Abnormally terminate this stream. This enqueues aRST_STREAMframe and returns immediately.- Parameters:
errorCode- the reason for closing the stream.
-