Package org.xnio.conduits
Class NullStreamSinkConduit
java.lang.Object
org.xnio.conduits.NullStreamSinkConduit
- All Implemented Interfaces:
Conduit
,SinkConduit
,StreamSinkConduit
A stream sink conduit which discards all data written to it.
- Author:
- David M. Lloyd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Block until this channel becomes writable again.void
awaitWritable
(long time, TimeUnit timeUnit) Block until this conduit becomes writable again, or until the timeout expires.boolean
flush()
Flush out any unwritten, buffered output.Get the XNIO worker associated with this conduit.Get the write thread for this conduit.boolean
Determine whether write notifications are currently enabled.boolean
Determine whether writes have been fully shut down on this conduit.void
Indicate that the conduit'sWriteReadyHandler
should be invoked as soon as data can be written without blocking.void
setWriteReadyHandler
(WriteReadyHandler handler) Set the handler which should receive readiness notifications.void
Indicate that calling the conduit'sWriteReadyHandler
should be suspended.void
Signal that no more write data is forthcoming.long
transferFrom
(FileChannel src, long position, long count) Transfer bytes into this conduit from the given file.long
transferFrom
(StreamSourceChannel source, long count, ByteBuffer throughBuffer) Transfers bytes from the given channel source.void
Terminate writes and discard any outstanding write data.void
Indicate that the conduit'sWriteReadyHandler
should be invoked immediately, and then again as soon as data can be written without blocking.int
write
(ByteBuffer src) Writes a sequence of bytes to this conduit from the given buffer.long
write
(ByteBuffer[] srcs, int offs, int len) Writes a sequence of bytes to this conduit from the given buffers.int
writeFinal
(ByteBuffer src) Writes some data to the conduit, with the same semantics asStreamSinkConduit.write(java.nio.ByteBuffer)
.long
writeFinal
(ByteBuffer[] srcs, int offset, int length) Writes some data to the conduit, with the same semantics asStreamSinkConduit.write(java.nio.ByteBuffer[], int, int)
.
-
Constructor Details
-
NullStreamSinkConduit
Construct a new instance.- Parameters:
writeThread
- the write thread for this conduit
-
-
Method Details
-
transferFrom
Description copied from interface:StreamSinkConduit
Transfer bytes into this conduit from the given file.- Specified by:
transferFrom
in 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:
IOException
- if an I/O error occurs
-
transferFrom
public long transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException Description copied from interface:StreamSinkConduit
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 thancount
, then the remaining data inthroughBuffer
may contain data read fromsource
which must be written to this channel to complete the operation.- Specified by:
transferFrom
in 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:
IOException
- if an I/O error occurs
-
write
Description copied from interface:StreamSinkConduit
Writes a sequence of bytes to this conduit from the given buffer.- Specified by:
write
in interfaceStreamSinkConduit
- Parameters:
src
- the buffer containing data to write- Returns:
- the number of bytes written, possibly 0
- Throws:
IOException
- if an error occurs
-
write
Description copied from interface:StreamSinkConduit
Writes a sequence of bytes to this conduit from the given buffers.- Specified by:
write
in 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:
IOException
- if an error occurs
-
writeFinal
Description copied from interface:StreamSinkConduit
Writes 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:
writeFinal
in interfaceStreamSinkConduit
- Parameters:
src
- The data to write- Returns:
- The amount of data that was actually written.
- Throws:
IOException
-
writeFinal
Description copied from interface:StreamSinkConduit
Writes 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:
writeFinal
in 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:
IOException
-
flush
Description copied from interface:SinkConduit
Flush out any unwritten, buffered output.- Specified by:
flush
in interfaceSinkConduit
- Returns:
true
if everything is flushed,false
otherwise- Throws:
IOException
- if flush fails
-
isWriteShutdown
public boolean isWriteShutdown()Description copied from interface:SinkConduit
Determine whether writes have been fully shut down on this conduit.- Specified by:
isWriteShutdown
in interfaceSinkConduit
- Returns:
true
if writes are fully shut down,false
otherwise
-
suspendWrites
public void suspendWrites()Description copied from interface:SinkConduit
Indicate that calling the conduit'sWriteReadyHandler
should be suspended.- Specified by:
suspendWrites
in interfaceSinkConduit
-
resumeWrites
public void resumeWrites()Description copied from interface:SinkConduit
Indicate that the conduit'sWriteReadyHandler
should be invoked as soon as data can be written without blocking.- Specified by:
resumeWrites
in interfaceSinkConduit
-
wakeupWrites
public void wakeupWrites()Description copied from interface:SinkConduit
Indicate that the conduit'sWriteReadyHandler
should be invoked immediately, and then again as soon as data can be written without blocking.- Specified by:
wakeupWrites
in interfaceSinkConduit
-
isWriteResumed
public boolean isWriteResumed()Description copied from interface:SinkConduit
Determine whether write notifications are currently enabled.- Specified by:
isWriteResumed
in interfaceSinkConduit
- Returns:
true
if write notifications are enabled
-
awaitWritable
Description copied from interface:SinkConduit
Block until this channel becomes writable again. This method may return spuriously before the channel becomes writable.- Specified by:
awaitWritable
in interfaceSinkConduit
- Throws:
IOException
- if an I/O error occurs
-
awaitWritable
Description copied from interface:SinkConduit
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.- Specified by:
awaitWritable
in interfaceSinkConduit
- Parameters:
time
- the time to waittimeUnit
- the time unit- Throws:
IOException
- if an I/O error occurs
-
getWriteThread
Description copied from interface:SinkConduit
Get the write thread for this conduit.- Specified by:
getWriteThread
in interfaceSinkConduit
- Returns:
- the thread, or
null
if none is configured or available
-
setWriteReadyHandler
Description copied from interface:SinkConduit
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.- Specified by:
setWriteReadyHandler
in interfaceSinkConduit
-
truncateWrites
Description copied from interface:SinkConduit
Terminate writes and discard any outstanding write data. The conduit is terminated and flushed regardless of the outcome of this method.- Specified by:
truncateWrites
in interfaceSinkConduit
- Throws:
IOException
- if channel termination failed for some reason
-
terminateWrites
Description copied from interface:SinkConduit
Signal that no more write data is forthcoming. The conduit must beSinkConduit.flush()
ed before it is considered to be shut down.- Specified by:
terminateWrites
in interfaceSinkConduit
- Throws:
IOException
-
getWorker
Description copied from interface:Conduit
Get the XNIO worker associated with this conduit.
-