- java.lang.Object
-
- org.xnio.conduits.NullStreamSinkConduit
-
- All Implemented Interfaces:
Conduit,SinkConduit,StreamSinkConduit
public final class NullStreamSinkConduit extends java.lang.Object implements StreamSinkConduit
A stream sink conduit which discards all data written to it.- Author:
- David M. Lloyd
-
-
Constructor Summary
Constructors Constructor Description NullStreamSinkConduit(XnioIoThread writeThread)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawaitWritable()Block until this channel becomes writable again.voidawaitWritable(long time, java.util.concurrent.TimeUnit timeUnit)Block until this conduit becomes writable again, or until the timeout expires.booleanflush()Flush out any unwritten, buffered output.XnioWorkergetWorker()Get the XNIO worker associated with this conduit.XnioIoThreadgetWriteThread()Get the write thread for this conduit.booleanisWriteResumed()Determine whether write notifications are currently enabled.booleanisWriteShutdown()Determine whether writes have been fully shut down on this conduit.voidresumeWrites()Indicate that the conduit'sWriteReadyHandlershould be invoked as soon as data can be written without blocking.voidsetWriteReadyHandler(WriteReadyHandler handler)Set the handler which should receive readiness notifications.voidsuspendWrites()Indicate that calling the conduit'sWriteReadyHandlershould be suspended.voidterminateWrites()Signal that no more write data is forthcoming.longtransferFrom(java.nio.channels.FileChannel src, long position, long count)Transfer bytes into this conduit from the given file.longtransferFrom(StreamSourceChannel source, long count, java.nio.ByteBuffer throughBuffer)Transfers bytes from the given channel source.voidtruncateWrites()Terminate writes and discard any outstanding write data.voidwakeupWrites()Indicate that the conduit'sWriteReadyHandlershould be invoked immediately, and then again as soon as data can be written without blocking.intwrite(java.nio.ByteBuffer src)Writes a sequence of bytes to this conduit from the given buffer.longwrite(java.nio.ByteBuffer[] srcs, int offs, int len)Writes a sequence of bytes to this conduit from the given buffers.intwriteFinal(java.nio.ByteBuffer src)Writes some data to the conduit, with the same semantics asStreamSinkConduit.write(java.nio.ByteBuffer).longwriteFinal(java.nio.ByteBuffer[] srcs, int offset, int length)Writes some data to the conduit, with the same semantics asStreamSinkConduit.write(java.nio.ByteBuffer[], int, int).
-
-
-
Constructor Detail
-
NullStreamSinkConduit
public NullStreamSinkConduit(XnioIoThread writeThread)
Construct a new instance.- Parameters:
writeThread- the write thread for this conduit
-
-
Method Detail
-
transferFrom
public long transferFrom(java.nio.channels.FileChannel src, long position, long count) throws java.io.IOExceptionDescription copied from interface:StreamSinkConduitTransfer bytes into this conduit from the given file.- Specified by:
transferFromin interfaceStreamSinkConduit- 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:
java.io.IOException- if an I/O error occurs
-
transferFrom
public long transferFrom(StreamSourceChannel source, long count, java.nio.ByteBuffer throughBuffer) throws java.io.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- 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:
java.io.IOException- if an I/O error occurs
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOExceptionDescription copied from interface:StreamSinkConduitWrites a sequence of bytes to this conduit from the given buffer.- Specified by:
writein interfaceStreamSinkConduit- Parameters:
src- the buffer containing data to write- Returns:
- the number of bytes written, possibly 0
- Throws:
java.nio.channels.ClosedChannelException- if this conduit'sSinkConduit.terminateWrites()method was previously calledjava.io.IOException- if an error occurs
-
write
public long write(java.nio.ByteBuffer[] srcs, int offs, int len) throws java.io.IOExceptionDescription copied from interface:StreamSinkConduitWrites a sequence of bytes to this conduit from the given buffers.- Specified by:
writein interfaceStreamSinkConduit- Parameters:
srcs- the buffers containing data to writeoffs- the offset into the buffer arraylen- the number of buffers to write- Returns:
- the number of bytes written, possibly 0
- Throws:
java.nio.channels.ClosedChannelException- if this conduit'sSinkConduit.terminateWrites()method was previously calledjava.io.IOException- if an error occurs
-
writeFinal
public int writeFinal(java.nio.ByteBuffer src) throws java.io.IOExceptionDescription 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- Parameters:
src- The data to write- Returns:
- The amount of data that was actually written.
- Throws:
java.io.IOException
-
writeFinal
public long writeFinal(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOExceptionDescription 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- 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:
java.io.IOException
-
flush
public boolean flush() throws java.io.IOExceptionDescription copied from interface:SinkConduitFlush out any unwritten, buffered output.- Specified by:
flushin interfaceSinkConduit- Returns:
trueif everything is flushed,falseotherwise- Throws:
java.io.IOException- if flush fails
-
isWriteShutdown
public boolean isWriteShutdown()
Description copied from interface:SinkConduitDetermine whether writes have been fully shut down on this conduit.- Specified by:
isWriteShutdownin interfaceSinkConduit- Returns:
trueif writes are fully shut down,falseotherwise
-
suspendWrites
public void suspendWrites()
Description copied from interface:SinkConduitIndicate that calling the conduit'sWriteReadyHandlershould be suspended.- Specified by:
suspendWritesin interfaceSinkConduit
-
resumeWrites
public void resumeWrites()
Description copied from interface:SinkConduitIndicate that the conduit'sWriteReadyHandlershould be invoked as soon as data can be written without blocking.- Specified by:
resumeWritesin interfaceSinkConduit
-
wakeupWrites
public void wakeupWrites()
Description copied from interface:SinkConduitIndicate that the conduit'sWriteReadyHandlershould be invoked immediately, and then again as soon as data can be written without blocking.- Specified by:
wakeupWritesin interfaceSinkConduit
-
isWriteResumed
public boolean isWriteResumed()
Description copied from interface:SinkConduitDetermine whether write notifications are currently enabled.- Specified by:
isWriteResumedin interfaceSinkConduit- Returns:
trueif write notifications are enabled
-
awaitWritable
public void awaitWritable() throws java.io.IOExceptionDescription copied from interface:SinkConduitBlock until this channel becomes writable again. This method may return spuriously before the channel becomes writable.- Specified by:
awaitWritablein interfaceSinkConduit- Throws:
java.io.InterruptedIOException- if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException- if an I/O error occurs
-
awaitWritable
public void awaitWritable(long time, java.util.concurrent.TimeUnit timeUnit) throws java.io.IOExceptionDescription copied from interface:SinkConduitBlock 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.- Specified by:
awaitWritablein interfaceSinkConduit- Parameters:
time- the time to waittimeUnit- the time unit- Throws:
java.io.InterruptedIOException- if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException- if an I/O error occurs
-
getWriteThread
public XnioIoThread getWriteThread()
Description copied from interface:SinkConduitGet the write thread for this conduit.- Specified by:
getWriteThreadin interfaceSinkConduit- Returns:
- the thread, or
nullif none is configured or available
-
setWriteReadyHandler
public void setWriteReadyHandler(WriteReadyHandler handler)
Description copied from interface:SinkConduitSet the handler which should receive readiness notifications. A filter may pass this invocation on to the filter it wraps, or it may substitute itself.- Specified by:
setWriteReadyHandlerin interfaceSinkConduit
-
truncateWrites
public void truncateWrites() throws java.io.IOExceptionDescription 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- Throws:
java.io.IOException- if channel termination failed for some reason
-
terminateWrites
public void terminateWrites() throws java.io.IOExceptionDescription 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- Throws:
java.io.IOException
-
getWorker
public XnioWorker getWorker()
Description copied from interface:ConduitGet the XNIO worker associated with this conduit.
-
-