Class Http2Stream

java.lang.Object
org.miaixz.bus.http.metric.http.Http2Stream

public class Http2Stream extends Object
逻辑双向流.
Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • getId

      public int getId()
    • isOpen

      public boolean isOpen()
      Returns true if this stream is open. A stream is open until either:
      • A SYN_RESET frame abnormally terminates the stream.
      • Both input and output streams have transmitted all data and headers.
      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.
    • isLocallyInitiated

      public boolean isLocallyInitiated()
      Returns true if this stream was created by this peer.
    • getConnection

      public Http2Connection getConnection()
    • takeHeaders

      public Headers takeHeaders() throws IOException
      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'.
      Throws:
      IOException
    • trailers

      public Headers trailers() throws IOException
      Returns the trailers. It is only safe to call this once the source stream has been completely exhausted.
      Throws:
      IOException
    • getErrorCode

      public Http2ErrorCode getErrorCode()
      Returns the reason why this stream was closed, or null if it closed normally or has not yet been closed.
    • writeHeaders

      public void writeHeaders(List<Http2Header> responseHeaders, boolean outFinished, boolean flushHeaders) throws IOException
      Sends a reply to an incoming stream.
      Parameters:
      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.
      Throws:
      IOException
    • enqueueTrailers

      public void enqueueTrailers(Headers trailers)
    • readTimeout

      public org.miaixz.bus.core.io.timout.Timeout readTimeout()
    • writeTimeout

      public org.miaixz.bus.core.io.timout.Timeout writeTimeout()
    • getSource

      public org.miaixz.bus.core.io.source.Source getSource()
      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.
      Throws:
      IllegalStateException - if this stream was initiated by the peer and a writeHeaders(java.util.List<org.miaixz.bus.http.metric.http.Http2Header>, boolean, boolean) has not yet been sent.
    • close

      public void close(Http2ErrorCode rstStatusCode, IOException errorException) throws IOException
      Abnormally terminate this stream. This blocks until the RST_STREAM frame has been transmitted.
      Throws:
      IOException
    • closeLater

      public void closeLater(Http2ErrorCode errorCode)
      Abnormally terminate this stream. This enqueues a RST_STREAM frame and returns immediately.