Module bus.http

Class Http2Stream

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

public class Http2Stream extends Object
A logical bidirectional stream.
Since:
Java 17+
Author:
Kimi Liu
  • 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_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.
      Returns:
      true if this stream is open.
    • 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

      public Http2Connection getConnection()
      Returns the connection that this stream is on.
      Returns:
      the connection that this stream is on.
    • 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'.
      Returns:
      the stream's received response headers.
      Throws:
      IOException - if an I/O error occurs.
    • trailers

      public Headers trailers() throws IOException
      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

      public Http2ErrorCode 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 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 - if an I/O error occurs.
    • enqueueTrailers

      public void enqueueTrailers(Headers trailers)
      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 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.
      Parameters:
      rstStatusCode - the reason for closing the stream.
      errorException - the exception that caused the closure.
      Throws:
      IOException - if an I/O error occurs.
    • closeLater

      public void closeLater(Http2ErrorCode errorCode)
      Abnormally terminate this stream. This enqueues a RST_STREAM frame and returns immediately.
      Parameters:
      errorCode - the reason for closing the stream.