- java.lang.Object
-
- org.xnio.channels.BlockingReadableByteChannel
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel,java.nio.channels.ScatteringByteChannel
public class BlockingReadableByteChannel extends java.lang.Object implements java.nio.channels.ScatteringByteChannelA blocking wrapper for aStreamSourceChannel. 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 aReadTimeoutExceptionif the timeout expires without reading any data.
-
-
Constructor Summary
Constructors Constructor Description BlockingReadableByteChannel(StreamSourceChannel delegate)Construct a new instance.BlockingReadableByteChannel(StreamSourceChannel delegate, long readTimeout, java.util.concurrent.TimeUnit readTimeoutUnit)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanisOpen()intread(java.nio.ByteBuffer dst)Perform a blocking read operation.longread(java.nio.ByteBuffer[] dsts)Perform a blocking, scattering read operation.longread(java.nio.ByteBuffer[] dsts, int offset, int length)Perform a blocking, scattering read operation.voidsetReadTimeout(long readTimeout, java.util.concurrent.TimeUnit readTimeoutUnit)Set the read timeout.
-
-
-
Constructor Detail
-
BlockingReadableByteChannel
public BlockingReadableByteChannel(StreamSourceChannel delegate)
Construct a new instance.- Parameters:
delegate- the channel to forward I/O operations to
-
BlockingReadableByteChannel
public BlockingReadableByteChannel(StreamSourceChannel delegate, long readTimeout, java.util.concurrent.TimeUnit readTimeoutUnit)
Construct a new instance.- Parameters:
delegate- the channel to forward I/O operations toreadTimeout- the read timeoutreadTimeoutUnit- the read timeout unit
-
-
Method Detail
-
setReadTimeout
public void setReadTimeout(long readTimeout, java.util.concurrent.TimeUnit readTimeoutUnit)Set the read timeout.- Parameters:
readTimeout- the read timeoutreadTimeoutUnit- the read timeout unit
-
read
public long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOExceptionPerform a blocking, scattering read operation.- Specified by:
readin interfacejava.nio.channels.ScatteringByteChannel- 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:
java.io.IOException- if an I/O error occurs
-
read
public long read(java.nio.ByteBuffer[] dsts) throws java.io.IOExceptionPerform a blocking, scattering read operation.- Specified by:
readin interfacejava.nio.channels.ScatteringByteChannel- Parameters:
dsts- the destination buffers- Returns:
- the number of bytes actually read (will be greater than zero)
- Throws:
java.io.IOException- if an I/O error occurs
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOExceptionPerform a blocking read operation.- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Parameters:
dst- the destination buffer- Returns:
- the number of bytes actually read (will be greater than zero)
- Throws:
java.io.IOException- if an I/O error occurs
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-