Interface Content.Sink

All Known Subinterfaces:
AuthenticationState.Deferred.DeferredResponse, Response, ServerUpgradeResponse, ServerUpgradeResponse
All Known Implementing Classes:
AsyncContent, AsyncRequestContent, BufferedContentSink, ContextResponse, GzipResponseAndCallback, HttpChannelState.ChannelResponse, Response.Wrapper, ServerUpgradeResponseDelegate, ServerUpgradeResponseImpl, ServletContextResponse, ServletCoreResponse, StatisticsHandler.MinimumDataRateHandler.MinimumDataRateResponse
Enclosing class:
Content

public static interface Content.Sink

A content sink that writes the content to its implementation (a socket, a file, etc.).

  • Method Details

    • asBuffered

      static Content.Sink asBuffered(Content.Sink sink, ByteBufferPool bufferPool, boolean direct, int maxAggregationSize, int maxBufferSize)

      Wraps the given content sink with a buffering sink.

      Parameters:
      sink - the sink to write to
      bufferPool - the ByteBufferPool to use
      direct - true to use direct buffers, false to use heap buffers
      maxAggregationSize - the maximum size that can be buffered in a single write; any size above this threshold triggers a buffer flush
      maxBufferSize - the maximum size of the buffer
      Returns:
      a Sink that writes to the given content sink
    • asOutputStream

      static OutputStream asOutputStream(Content.Sink sink)

      Wraps the given content sink with an OutputStream.

      Parameters:
      sink - the sink to write to
      Returns:
      an OutputStream that writes to the content sink
    • asSubscriber

      static Flow.Subscriber<Content.Chunk> asSubscriber(Content.Sink sink, Callback callback)

      Wraps the given content sink with a Flow.Subscriber.

      Parameters:
      sink - the sink to write to
      callback - the callback to notify when the Subscriber is complete
      Returns:
      a Subscriber that writes to the content sink
    • write

      static void write(Content.Sink sink, boolean last, ByteBuffer byteBuffer) throws IOException
      Parameters:
      sink - the sink to write to
      last - whether the ByteBuffers are the last to write
      byteBuffer - the ByteBuffers to write
      Throws:
      IOException - if the write operation fails
    • write

      static void write(Content.Sink sink, boolean last, String utf8Content, Callback callback)

      Writes the given String, converting it to UTF-8 bytes, notifying the Callback when the write is complete.

      Parameters:
      last - whether the String is the last to write
      utf8Content - the String to write
      callback - the callback to notify when the write operation is complete. Implementations have the same guarantees for invocation of this callback as for write(boolean, ByteBuffer, Callback).
    • write

      void write(boolean last, ByteBuffer byteBuffer, Callback callback)

      Writes the given ByteBuffer, notifying the Callback when the write is complete.

      Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Callback and a call to this method.

      Parameters:
      last - whether the ByteBuffer is the last to write
      byteBuffer - the ByteBuffer to write
      callback - the callback to notify when the write operation is complete