Package org.xnio.conduits
Class DeflatingStreamSinkConduit
java.lang.Object
org.xnio.conduits.AbstractConduit<D>
org.xnio.conduits.AbstractSinkConduit<D>
org.xnio.conduits.AbstractStreamSinkConduit<StreamSinkConduit>
org.xnio.conduits.DeflatingStreamSinkConduit
- All Implemented Interfaces:
Conduit,SinkConduit,StreamSinkConduit
public final class DeflatingStreamSinkConduit
extends AbstractStreamSinkConduit<StreamSinkConduit>
implements StreamSinkConduit
A filtering stream sink conduit which compresses the written data.
- Author:
- David M. Lloyd
-
Field Summary
Fields inherited from class org.xnio.conduits.AbstractConduit
next -
Constructor Summary
ConstructorsConstructorDescriptionDeflatingStreamSinkConduit(StreamSinkConduit next, Deflater deflater) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanflush()Flush out any unwritten, buffered output.voidSignal that no more write data is forthcoming.longtransferFrom(FileChannel src, long position, long count) Transfer bytes into this conduit from the given file.longtransferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) Transfers bytes from the given channel source.voidTerminate writes and discard any outstanding write data.intwrite(ByteBuffer src) Writes a sequence of bytes to this conduit from the given buffer.longwrite(ByteBuffer[] srcs, int offset, int length) Writes a sequence of bytes to this conduit from the given buffers.intwriteFinal(ByteBuffer src) Writes some data to the conduit, with the same semantics asStreamSinkConduit.write(java.nio.ByteBuffer).longwriteFinal(ByteBuffer[] srcs, int offset, int length) Writes some data to the conduit, with the same semantics asStreamSinkConduit.write(java.nio.ByteBuffer[], int, int).Methods inherited from class org.xnio.conduits.AbstractSinkConduit
awaitWritable, awaitWritable, getWriteThread, isWriteResumed, isWriteShutdown, resumeWrites, setWriteReadyHandler, suspendWrites, wakeupWritesMethods inherited from class org.xnio.conduits.AbstractConduit
getWorkerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xnio.conduits.SinkConduit
awaitWritable, awaitWritable, getWriteThread, isWriteResumed, isWriteShutdown, resumeWrites, setWriteReadyHandler, suspendWrites, wakeupWrites
-
Constructor Details
-
DeflatingStreamSinkConduit
Construct a new instance.- Parameters:
next- the delegate conduit to setdeflater- the initialized deflater to use
-
-
Method Details
-
transferFrom
Description copied from interface:StreamSinkConduitTransfer bytes into this conduit from the given file.- Specified by:
transferFromin interfaceStreamSinkConduit- Overrides:
transferFromin classAbstractStreamSinkConduit<StreamSinkConduit>- Parameters:
src- the file to read fromposition- the position within the file from which the transfer is to begincount- the number of bytes to be transferred- Returns:
- the number of bytes (possibly 0) that were actually transferred
- Throws:
IOException- if an I/O error occurs
-
transferFrom
public long transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException Description copied from interface:StreamSinkConduitTransfers bytes from the given channel source. On entry,throughBufferwill 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 thancount, then the remaining data inthroughBuffermay contain data read fromsourcewhich must be written to this channel to complete the operation.- Specified by:
transferFromin interfaceStreamSinkConduit- Overrides:
transferFromin classAbstractStreamSinkConduit<StreamSinkConduit>- Parameters:
source- the source to read fromcount- the number of bytes to be transferredthroughBuffer- the buffer to copy through.- Returns:
- the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached
- Throws:
IOException- if an I/O error occurs
-
write
Description copied from interface:StreamSinkConduitWrites a sequence of bytes to this conduit from the given buffer.- Specified by:
writein interfaceStreamSinkConduit- Overrides:
writein classAbstractStreamSinkConduit<StreamSinkConduit>- Parameters:
src- the buffer containing data to write- Returns:
- the number of bytes written, possibly 0
- Throws:
ClosedChannelException- if this conduit'sSinkConduit.terminateWrites()method was previously calledIOException- if an error occurs
-
write
Description copied from interface:StreamSinkConduitWrites a sequence of bytes to this conduit from the given buffers.- Specified by:
writein interfaceStreamSinkConduit- Overrides:
writein classAbstractStreamSinkConduit<StreamSinkConduit>- Parameters:
srcs- the buffers containing data to writeoffset- the offset into the buffer arraylength- the number of buffers to write- Returns:
- the number of bytes written, possibly 0
- Throws:
ClosedChannelException- if this conduit'sSinkConduit.terminateWrites()method was previously calledIOException- if an error occurs
-
flush
Description copied from interface:SinkConduitFlush out any unwritten, buffered output.- Specified by:
flushin interfaceSinkConduit- Overrides:
flushin classAbstractSinkConduit<StreamSinkConduit>- Returns:
trueif everything is flushed,falseotherwise- Throws:
IOException- if flush fails
-
writeFinal
Description copied from interface:StreamSinkConduitWrites some data to the conduit, with the same semantics asStreamSinkConduit.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() }- Specified by:
writeFinalin interfaceStreamSinkConduit- Overrides:
writeFinalin classAbstractStreamSinkConduit<StreamSinkConduit>- Parameters:
src- The data to write- Returns:
- The amount of data that was actually written.
- Throws:
IOException
-
writeFinal
Description copied from interface:StreamSinkConduitWrites some data to the conduit, with the same semantics asStreamSinkConduit.write(java.nio.ByteBuffer[], int, int). If all the data is written out then the conduit will have its writes terminated.- Specified by:
writeFinalin interfaceStreamSinkConduit- Overrides:
writeFinalin classAbstractStreamSinkConduit<StreamSinkConduit>- Parameters:
srcs- The buffers from which bytes are to be retrievedoffset- 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.lengthlength- The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset- Returns:
- The amount of data that was actually written
- Throws:
IOException
-
terminateWrites
Description copied from interface:SinkConduitSignal that no more write data is forthcoming. The conduit must beSinkConduit.flush()ed before it is considered to be shut down.- Specified by:
terminateWritesin interfaceSinkConduit- Overrides:
terminateWritesin classAbstractSinkConduit<StreamSinkConduit>- Throws:
IOException
-
truncateWrites
Description copied from interface:SinkConduitTerminate writes and discard any outstanding write data. The conduit is terminated and flushed regardless of the outcome of this method.- Specified by:
truncateWritesin interfaceSinkConduit- Overrides:
truncateWritesin classAbstractSinkConduit<StreamSinkConduit>- Throws:
IOException- if channel termination failed for some reason
-