- java.lang.Object
-
- org.xnio.conduits.AbstractConduit<D>
-
- org.xnio.conduits.AbstractSourceConduit<D>
-
- org.xnio.conduits.AbstractStreamSourceConduit<StreamSourceConduit>
-
- org.xnio.conduits.BlockingStreamSourceConduit
-
- All Implemented Interfaces:
Conduit
,SourceConduit
,StreamSourceConduit
public final class BlockingStreamSourceConduit extends AbstractStreamSourceConduit<StreamSourceConduit>
A stream source conduit which can switch into and out of blocking mode.- Author:
- David M. Lloyd
-
-
Field Summary
-
Fields inherited from class org.xnio.conduits.AbstractConduit
next
-
-
Constructor Summary
Constructors Constructor Description BlockingStreamSourceConduit(StreamSourceConduit next)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isReadResumed()
Determine whether read notifications are currently enabled.int
read(java.nio.ByteBuffer dst)
Read a sequence of bytes from this conduit to the given buffer.long
read(java.nio.ByteBuffer[] dsts, int offs, int len)
Read a sequence of bytes from this conduit to the given buffers.void
resumeReads()
Indicate that the conduit'sReadReadyHandler
should be invoked as soon as data can be read without blocking.void
suspendReads()
Indicate that calling the conduit'sReadReadyHandler
should be suspended.long
transferTo(long position, long count, java.nio.channels.FileChannel target)
Transfers bytes into the given file from this channel.long
transferTo(long count, java.nio.ByteBuffer throughBuffer, StreamSinkChannel target)
Transfers bytes into the given channel target.void
wakeupReads()
Indicate that the conduit'sReadReadyHandler
should be invoked immediately, and then again as soon as data can be read without blocking.-
Methods inherited from class org.xnio.conduits.AbstractSourceConduit
awaitReadable, awaitReadable, getReadThread, isReadShutdown, setReadReadyHandler, terminateReads
-
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.SourceConduit
awaitReadable, awaitReadable, getReadThread, isReadShutdown, setReadReadyHandler, terminateReads
-
-
-
-
Constructor Detail
-
BlockingStreamSourceConduit
public BlockingStreamSourceConduit(StreamSourceConduit next)
Construct a new instance.- Parameters:
next
- the delegate conduit to set
-
-
Method Detail
-
transferTo
public long transferTo(long position, long count, java.nio.channels.FileChannel target) throws java.io.IOException
Description copied from interface:StreamSourceConduit
Transfers bytes into the given file from this channel.- Specified by:
transferTo
in interfaceStreamSourceConduit
- Overrides:
transferTo
in classAbstractStreamSourceConduit<StreamSourceConduit>
- Parameters:
position
- the position within the file from which the transfer is to begincount
- the number of bytes to be transferredtarget
- the file to write to- Returns:
- the number of bytes (possibly 0) that were actually transferred
- Throws:
java.io.IOException
- if an I/O error occurs
-
transferTo
public long transferTo(long count, java.nio.ByteBuffer throughBuffer, StreamSinkChannel target) throws java.io.IOException
Description copied from interface:StreamSourceConduit
Transfers bytes into the given channel target. On entry,throughBuffer
will be cleared. On exit, the buffer will be flipped for emptying, and may possibly be empty or may contain data. If this method returns a value less thancount
, then the remaining data inthroughBuffer
may contain data read from this channel which must be written totarget
to complete the operation.- Specified by:
transferTo
in interfaceStreamSourceConduit
- Overrides:
transferTo
in classAbstractStreamSourceConduit<StreamSourceConduit>
- Parameters:
count
- the number of bytes to be transferredthroughBuffer
- the buffer to copy through.target
- the destination to write to- 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
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
Description copied from interface:StreamSourceConduit
Read a sequence of bytes from this conduit to the given buffer.- Specified by:
read
in interfaceStreamSourceConduit
- Overrides:
read
in classAbstractStreamSourceConduit<StreamSourceConduit>
- Returns:
- the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or
this conduit's
SourceConduit.terminateReads()
method was previously called - Throws:
java.io.IOException
- if an error occurs
-
read
public long read(java.nio.ByteBuffer[] dsts, int offs, int len) throws java.io.IOException
Description copied from interface:StreamSourceConduit
Read a sequence of bytes from this conduit to the given buffers.- Specified by:
read
in interfaceStreamSourceConduit
- Overrides:
read
in classAbstractStreamSourceConduit<StreamSourceConduit>
offs
- the offset into the buffer arraylen
- the number of buffers to fill- Returns:
- the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or
this conduit's
SourceConduit.terminateReads()
method was previously called - Throws:
java.io.IOException
- if an error occurs
-
resumeReads
public void resumeReads()
Description copied from interface:SourceConduit
Indicate that the conduit'sReadReadyHandler
should be invoked as soon as data can be read without blocking.- Specified by:
resumeReads
in interfaceSourceConduit
- Overrides:
resumeReads
in classAbstractSourceConduit<StreamSourceConduit>
-
wakeupReads
public void wakeupReads()
Description copied from interface:SourceConduit
Indicate that the conduit'sReadReadyHandler
should be invoked immediately, and then again as soon as data can be read without blocking.- Specified by:
wakeupReads
in interfaceSourceConduit
- Overrides:
wakeupReads
in classAbstractSourceConduit<StreamSourceConduit>
-
suspendReads
public void suspendReads()
Description copied from interface:SourceConduit
Indicate that calling the conduit'sReadReadyHandler
should be suspended.- Specified by:
suspendReads
in interfaceSourceConduit
- Overrides:
suspendReads
in classAbstractSourceConduit<StreamSourceConduit>
-
isReadResumed
public boolean isReadResumed()
Description copied from interface:SourceConduit
Determine whether read notifications are currently enabled.- Specified by:
isReadResumed
in interfaceSourceConduit
- Overrides:
isReadResumed
in classAbstractSourceConduit<StreamSourceConduit>
- Returns:
true
if read notifications are enabled
-
-