Top Description Fields Constructors Methods
io.undertow.conduits

public Class DeflatingStreamSinkConduit

extends Object
implements StreamSinkConduit
Class Inheritance
All Implemented Interfaces
org.xnio.conduits.StreamSinkConduit, org.xnio.conduits.SinkConduit, org.xnio.conduits.Conduit
Known Direct Subclasses
io.undertow.conduits.GzipStreamSinkConduit
Static Imports
org.xnio.Bits.allAreClear, .Bits.allAreSet, .Bits.anyAreSet

Channel that handles deflate compression
Author
Stuart Douglas

Field Summary

Modifier and TypeField and Description
private static final int
private final ConduitFactory<StreamSinkConduit>
protected PooledByteBuffer
currentBuffer

The streams buffer.

protected volatile Deflater
private static final ByteBuffer
private final HttpServerExchange
private static final int
private StreamSinkConduit
private static final int
protected final PooledObject<Deflater>
private static final int
private int
private ByteBuffer
trailerBuffer

Buffer used to write the trailer if currentBuffer doesn't have enough space.

private WriteReadyHandler
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public
public
DeflatingStreamSinkConduit(final ConduitFactory<StreamSinkConduit> conduitFactory, final HttpServerExchange exchange, int deflateLevel)

public

Method Summary

Modifier and TypeMethod and Description
public void
awaitWritable()

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Block until this channel becomes writable again.

public void
awaitWritable(final long
the time to wait
time
,
final TimeUnit
the time unit
timeUnit
)

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Block until this conduit becomes writable again, or until the timeout expires.

private StreamSinkConduit
private void
deflateData(boolean force)

Runs the current data through the deflater.

public boolean
flush()

Implements org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

private void
protected byte[]
getTrailer()

called before the stream is finally flushed.

public XnioWorker
getWorker()

Implements org.xnio.conduits.Conduit.getWorker.

Get the XNIO worker associated with this conduit.

public XnioIoThread
getWriteThread()

Implements org.xnio.conduits.SinkConduit.getWriteThread.

Get the write thread for this conduit.

public boolean
isWriteResumed()

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

public boolean
isWriteShutdown()

Implements org.xnio.conduits.SinkConduit.isWriteShutdown.

Determine whether writes have been fully shut down on this conduit.

public static ObjectPool<Deflater>
newInstanceDeflaterPool(int deflateLevel)

private boolean

Returns:

false if there is still more to flush
performFlushIfRequired
()

The we are in the flushing state then we flush to the underlying stream, otherwise just return true

private boolean
private boolean
protected void
private void
public void
resumeWrites()

Implements org.xnio.conduits.SinkConduit.resumeWrites.

Indicate that the conduit's WriteReadyHandler should be invoked as soon as data can be written without blocking.

public void
setWriteReadyHandler(final WriteReadyHandler
the filter to receive readiness notifications
handler
)

Implements org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Set the handler which should receive readiness notifications.

public static ObjectPool<Deflater>
simpleDeflaterPool(int poolSize, int deflateLevel)

public void
suspendWrites()

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

public void
terminateWrites()

Implements org.xnio.conduits.SinkConduit.terminateWrites.

Signal that no more write data is forthcoming.

public long
transferFrom(final FileChannel
the file to read from
src
,
final long
the position within the file from which the transfer is to begin
position
,
final long
the number of bytes to be transferred
count
)

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

public long
transferFrom(final StreamSourceChannel
the source to read from
source
,
final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
)

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source.

public void
truncateWrites()

Implements org.xnio.conduits.SinkConduit.truncateWrites.

Terminate writes and discard any outstanding write data.

public void
wakeupWrites()

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

public int
write(final ByteBuffer
the buffer containing data to write
src
)

Implements org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffer.

public long
write(final ByteBuffer[]
the buffers containing data to write
srcs
,
final int
the offset into the buffer array
offset
,
final int
the number of buffers to write
length
)

Implements org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffers.

public int
writeFinal(ByteBuffer
The data to write
src
)

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer).

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLOSEDback to summary
private static final int CLOSED
conduitFactoryback to summary
private final ConduitFactory<StreamSinkConduit> conduitFactory
currentBufferback to summary
protected PooledByteBuffer currentBuffer

The streams buffer. This is freed when the next is shutdown

deflaterback to summary
protected volatile Deflater deflater
EMPTYback to summary
private static final ByteBuffer EMPTY
exchangeback to summary
private final HttpServerExchange exchange
FLUSHING_BUFFERback to summary
private static final int FLUSHING_BUFFER
nextback to summary
private StreamSinkConduit next
NEXT_SHUTDOWNback to summary
private static final int NEXT_SHUTDOWN
pooledObjectback to summary
protected final PooledObject<Deflater> pooledObject
SHUTDOWNback to summary
private static final int SHUTDOWN
stateback to summary
private int state
trailerBufferback to summary
private ByteBuffer trailerBuffer

Buffer used to write the trailer if currentBuffer doesn't have enough space.

writeReadyHandlerback to summary
private WriteReadyHandler writeReadyHandler
WRITES_RESUMEDback to summary
private static final int WRITES_RESUMED
WRITTEN_TRAILERback to summary
private static final int WRITTEN_TRAILER

Constructor Detail

DeflatingStreamSinkConduitback to summary
public DeflatingStreamSinkConduit(final ConduitFactory<StreamSinkConduit> conduitFactory, final HttpServerExchange exchange)
DeflatingStreamSinkConduitback to summary
public DeflatingStreamSinkConduit(final ConduitFactory<StreamSinkConduit> conduitFactory, final HttpServerExchange exchange, int deflateLevel)
DeflatingStreamSinkConduitback to summary
public DeflatingStreamSinkConduit(final ConduitFactory<StreamSinkConduit> conduitFactory, final HttpServerExchange exchange, ObjectPool<Deflater> deflaterPool)

Method Detail

awaitWritableback to summary
public void awaitWritable() throws IOException

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Doc from org.xnio.conduits.SinkConduit.awaitWritable.

Block until this channel becomes writable again. This method may return spuriously before the channel becomes writable.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
awaitWritableback to summary
public void awaitWritable(final long time, final TimeUnit timeUnit) throws IOException

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Doc from org.xnio.conduits.SinkConduit.awaitWritable.

Block until this conduit becomes writable again, or until the timeout expires. This method may return spuriously before the conduit becomes writable or the timeout expires.

Parameters
time:long

the time to wait

timeUnit:TimeUnit

the time unit

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
createNextChannelback to summary
private StreamSinkConduit createNextChannel()
deflateDataback to summary
private void deflateData(boolean force) throws IOException

Runs the current data through the deflater. As much as possible this will be buffered in the current output stream.

flushback to summary
public boolean flush() throws IOException

Implements org.xnio.conduits.SinkConduit.flush.

Doc from org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

Returns:boolean

true if everything is flushed, false otherwise

Annotations
@Override
Exceptions
IOException:
if flush fails
freeBufferback to summary
private void freeBuffer()
getTrailerback to summary
protected byte[] getTrailer()

called before the stream is finally flushed.

getWorkerback to summary
public XnioWorker getWorker()

Implements org.xnio.conduits.Conduit.getWorker.

Doc from org.xnio.conduits.Conduit.getWorker.

Get the XNIO worker associated with this conduit.

Returns:XnioWorker

the XNIO worker associated with this conduit

Annotations
@Override
getWriteThreadback to summary
public XnioIoThread getWriteThread()

Implements org.xnio.conduits.SinkConduit.getWriteThread.

Doc from org.xnio.conduits.SinkConduit.getWriteThread.

Get the write thread for this conduit.

Returns:XnioIoThread

the thread, or null if none is configured or available

Annotations
@Override
isWriteResumedback to summary
public boolean isWriteResumed()

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Doc from org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

Returns:boolean

true if write notifications are enabled

Annotations
@Override
isWriteShutdownback to summary
public boolean isWriteShutdown()

Implements org.xnio.conduits.SinkConduit.isWriteShutdown.

Doc from org.xnio.conduits.SinkConduit.isWriteShutdown.

Determine whether writes have been fully shut down on this conduit.

Returns:boolean

true if writes are fully shut down, false otherwise

Annotations
@Override
newInstanceDeflaterPoolback to summary
public static ObjectPool<Deflater> newInstanceDeflaterPool(int deflateLevel)
performFlushIfRequiredback to summary
private boolean performFlushIfRequired() throws IOException

The we are in the flushing state then we flush to the underlying stream, otherwise just return true

Returns:boolean

false if there is still more to flush

performFlushIfRequiredAdditionalBufferback to summary
private boolean performFlushIfRequiredAdditionalBuffer() throws IOException
performFlushIfRequiredSingleBufferback to summary
private boolean performFlushIfRequiredSingleBuffer() throws IOException
postDeflateback to summary
protected void postDeflate(ByteBuffer data)
queueWriteListenerback to summary
private void queueWriteListener()
resumeWritesback to summary
public void resumeWrites()

Implements org.xnio.conduits.SinkConduit.resumeWrites.

Doc from org.xnio.conduits.SinkConduit.resumeWrites.

Indicate that the conduit's WriteReadyHandler should be invoked as soon as data can be written without blocking.

Annotations
@Override
setWriteReadyHandlerback to summary
public void setWriteReadyHandler(final WriteReadyHandler handler)

Implements org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Doc from org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Set the handler which should receive readiness notifications. A filter may pass this invocation on to the filter it wraps, or it may substitute itself.

Parameters
handler:WriteReadyHandler

the filter to receive readiness notifications

Annotations
@Override
simpleDeflaterPoolback to summary
public static ObjectPool<Deflater> simpleDeflaterPool(int poolSize, int deflateLevel)
suspendWritesback to summary
public void suspendWrites()

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Doc from org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

Annotations
@Override
terminateWritesback to summary
public void terminateWrites() throws IOException

Implements org.xnio.conduits.SinkConduit.terminateWrites.

Doc from org.xnio.conduits.SinkConduit.terminateWrites.

Signal that no more write data is forthcoming. The conduit must be flush()ed before it is considered to be shut down.

Annotations
@Override
transferFromback to summary
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

Parameters
src:FileChannel

the file to read from

position:long

the position within the file from which the transfer is to begin

count:long

the number of bytes to be transferred

Returns:long

the number of bytes (possibly 0) that were actually transferred

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
transferFromback to summary
public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source. On entry, throughBuffer will be cleared. On exit, the buffer will be flipped for emptying, and may be empty or may contain data. If this method returns a value less than count, then the remaining data in throughBuffer may contain data read from source which must be written to this channel to complete the operation.

Parameters
source:StreamSourceChannel

the source to read from

count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
truncateWritesback to summary
public void truncateWrites() throws IOException

Implements org.xnio.conduits.SinkConduit.truncateWrites.

Doc from org.xnio.conduits.SinkConduit.truncateWrites.

Terminate writes and discard any outstanding write data. The conduit is terminated and flushed regardless of the outcome of this method.

Annotations
@Override
Exceptions
IOException:
if channel termination failed for some reason
wakeupWritesback to summary
public void wakeupWrites()

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Doc from org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

Annotations
@Override
writeback to summary
public int write(final ByteBuffer src) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffer.

Parameters
src:ByteBuffer

the buffer containing data to write

Returns:int

the number of bytes written, possibly 0

Annotations
@Override
Exceptions
IOException:
if an error occurs
writeback to summary
public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffers.

Parameters
srcs:ByteBuffer[]

the buffers containing data to write

offset:int

the offset into the buffer array

length:int

the number of buffers to write

Returns:long

the number of bytes written, possibly 0

Annotations
@Override
Exceptions
IOException:
if an error occurs
writeFinalback to summary
public int writeFinal(ByteBuffer src) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer). If all the data is written out then the conduit will have its writes terminated. Semantically this method is equivalent to: int rem = src.remaining(); int written = conduit.write(src); if(written == rem) { conduit.terminateWrites() }

Parameters
src:ByteBuffer

The data to write

Returns:int

The amount of data that was actually written.

Annotations
@Override
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int). If all the data is written out then the conduit will have its writes terminated.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

offset:int

The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length

length:int

The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset

Returns:long

The amount of data that was actually written

Annotations
@Override