Package org.xnio.channels
Class BlockingReadableByteChannel
java.lang.Object
org.xnio.channels.BlockingReadableByteChannel
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,ReadableByteChannel
,ScatteringByteChannel
A blocking wrapper for a
StreamSourceChannel
. Read operations will block until some data may be transferred.
Once any amount of data is read, the operation will return. If a read timeout is specified, then the read methods
will throw a ReadTimeoutException
if the timeout expires without reading any data.-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance.BlockingReadableByteChannel
(StreamSourceChannel delegate, long readTimeout, TimeUnit readTimeoutUnit) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
isOpen()
int
read
(ByteBuffer dst) Perform a blocking read operation.long
read
(ByteBuffer[] dsts) Perform a blocking, scattering read operation.long
read
(ByteBuffer[] dsts, int offset, int length) Perform a blocking, scattering read operation.void
setReadTimeout
(long readTimeout, TimeUnit readTimeoutUnit) Set the read timeout.
-
Constructor Details
-
BlockingReadableByteChannel
Construct a new instance.- Parameters:
delegate
- the channel to forward I/O operations to
-
BlockingReadableByteChannel
public BlockingReadableByteChannel(StreamSourceChannel delegate, long readTimeout, TimeUnit readTimeoutUnit) Construct a new instance.- Parameters:
delegate
- the channel to forward I/O operations toreadTimeout
- the read timeoutreadTimeoutUnit
- the read timeout unit
-
-
Method Details
-
setReadTimeout
Set the read timeout.- Parameters:
readTimeout
- the read timeoutreadTimeoutUnit
- the read timeout unit
-
read
Perform a blocking, scattering read operation.- Specified by:
read
in interfaceScatteringByteChannel
- Parameters:
dsts
- the destination buffersoffset
- the offset into the destination buffer arraylength
- the number of buffers to read into- Returns:
- the number of bytes actually read (will be greater than zero)
- Throws:
IOException
- if an I/O error occurs
-
read
Perform a blocking, scattering read operation.- Specified by:
read
in interfaceScatteringByteChannel
- Parameters:
dsts
- the destination buffers- Returns:
- the number of bytes actually read (will be greater than zero)
- Throws:
IOException
- if an I/O error occurs
-
read
Perform a blocking read operation.- Specified by:
read
in interfaceReadableByteChannel
- Parameters:
dst
- the destination buffer- Returns:
- the number of bytes actually read (will be greater than zero)
- Throws:
IOException
- if an I/O error occurs
-
isOpen
public boolean isOpen() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-