Package org.eclipse.jetty.io
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 Summary
Modifier and TypeMethodDescriptionstatic Content.Sink
asBuffered
(Content.Sink sink, ByteBufferPool bufferPool, boolean direct, int maxAggregationSize, int maxBufferSize) Wraps the given content sink with a buffering sink.static OutputStream
asOutputStream
(Content.Sink sink) Wraps the given content sink with anOutputStream
.static Flow.Subscriber<Content.Chunk>
asSubscriber
(Content.Sink sink, Callback callback) Wraps the given content sink with aFlow.Subscriber
.void
write
(boolean last, ByteBuffer byteBuffer, Callback callback) Writes the givenByteBuffer
, notifying theCallback
when the write is complete.static void
write
(Content.Sink sink, boolean last, String utf8Content, Callback callback) static void
write
(Content.Sink sink, boolean last, ByteBuffer byteBuffer) Blocking version ofwrite(boolean, ByteBuffer, Callback)
.
-
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 tobufferPool
- theByteBufferPool
to usedirect
- true to use direct buffers, false to use heap buffersmaxAggregationSize
- the maximum size that can be buffered in a single write; any size above this threshold triggers a buffer flushmaxBufferSize
- the maximum size of the buffer- Returns:
- a Sink that writes to the given content sink
-
asOutputStream
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
Wraps the given content sink with a
Flow.Subscriber
.- Parameters:
sink
- the sink to write tocallback
- the callback to notify when the Subscriber is complete- Returns:
- a Subscriber that writes to the content sink
-
write
Blocking version of
write(boolean, ByteBuffer, Callback)
.- Parameters:
sink
- the sink to write tolast
- whether the ByteBuffers are the last to writebyteBuffer
- the ByteBuffers to write- Throws:
IOException
- if the write operation fails
-
write
Writes the given
String
, converting it to UTF-8 bytes, notifying theCallback
when the write is complete.- Parameters:
last
- whether the String is the last to writeutf8Content
- the String to writecallback
- the callback to notify when the write operation is complete. Implementations have the same guarantees for invocation of this callback as forwrite(boolean, ByteBuffer, Callback)
.
-
write
Writes the given
ByteBuffer
, notifying theCallback
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 writebyteBuffer
- the ByteBuffer to writecallback
- the callback to notify when the write operation is complete
-