Package org.xnio.conduits
Class SynchronizedStreamSinkConduit
java.lang.Object
org.xnio.conduits.AbstractConduit<D>
org.xnio.conduits.AbstractSynchronizedConduit<D>
org.xnio.conduits.AbstractSynchronizedSinkConduit<StreamSinkConduit>
org.xnio.conduits.SynchronizedStreamSinkConduit
- All Implemented Interfaces:
Conduit
,SinkConduit
,StreamSinkConduit
public final class SynchronizedStreamSinkConduit
extends AbstractSynchronizedSinkConduit<StreamSinkConduit>
implements StreamSinkConduit
A synchronized stream sink conduit. All conduit operations are wrapped in synchronization blocks for simplified
thread safety.
- Author:
- David M. Lloyd
-
Field Summary
Fields inherited from class org.xnio.conduits.AbstractSynchronizedConduit
lock
Fields inherited from class org.xnio.conduits.AbstractConduit
next
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance.SynchronizedStreamSinkConduit
(StreamSinkConduit next, Object lock) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionlong
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.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)
.Methods inherited from class org.xnio.conduits.AbstractSynchronizedSinkConduit
awaitWritable, awaitWritable, flush, getWriteThread, isWriteResumed, isWriteShutdown, resumeWrites, setWriteReadyHandler, suspendWrites, terminateWrites, truncateWrites, wakeupWrites
Methods inherited from class org.xnio.conduits.AbstractConduit
getWorker
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xnio.conduits.SinkConduit
awaitWritable, awaitWritable, flush, getWriteThread, isWriteResumed, isWriteShutdown, resumeWrites, setWriteReadyHandler, suspendWrites, terminateWrites, truncateWrites, wakeupWrites
-
Constructor Details
-
SynchronizedStreamSinkConduit
Construct a new instance. A new lock object is created.- Parameters:
next
- the next conduit in the chain
-
SynchronizedStreamSinkConduit
Construct a new instance.- Parameters:
next
- the next conduit in the chainlock
- the lock object to use
-
-
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:
ClosedChannelException
- if this conduit'sSinkConduit.terminateWrites()
method was previously calledIOException
- 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:
ClosedChannelException
- if this conduit'sSinkConduit.terminateWrites()
method was previously calledIOException
- 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
-