Package org.xnio.channels
Class BlockingByteChannel
java.lang.Object
org.xnio.channels.BlockingByteChannel
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,ByteChannel,Channel,GatheringByteChannel,ReadableByteChannel,ScatteringByteChannel,WritableByteChannel
public class BlockingByteChannel
extends Object
implements ScatteringByteChannel, GatheringByteChannel, ByteChannel, Flushable
A blocking wrapper for a
StreamChannel. Read and write operations will block until some data may be transferred.
Once any amount of data is read or written, 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. If a write timeout is specified, then the write methods
will throw a WriteTimeoutException if the timeout expires without writing any data.-
Constructor Summary
ConstructorsConstructorDescriptionBlockingByteChannel(StreamChannel delegate) Construct a new instance.BlockingByteChannel(StreamChannel delegate, long timeout, TimeUnit timeoutUnit) Construct a new instance.BlockingByteChannel(StreamChannel delegate, long readTimeout, TimeUnit readTimeoutUnit, long writeTimeout, TimeUnit writeTimeoutUnit) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()booleanisOpen()intread(ByteBuffer dst) Perform a blocking read operation.longread(ByteBuffer[] dsts) Perform a blocking, scattering read operation.longread(ByteBuffer[] dsts, int offset, int length) Perform a blocking, scattering read operation.voidsetReadTimeout(long readTimeout, TimeUnit readTimeoutUnit) Set the read timeout.voidsetWriteTimeout(long writeTimeout, TimeUnit writeTimeoutUnit) Set the write timeout.intwrite(ByteBuffer src) Perform a blocking write operation.longwrite(ByteBuffer[] srcs) Perform a blocking, gathering write operation.longwrite(ByteBuffer[] srcs, int offset, int length) Perform a blocking, gathering write operation.
-
Constructor Details
-
BlockingByteChannel
Construct a new instance.- Parameters:
delegate- the channel to forward I/O operations to
-
BlockingByteChannel
Construct a new instance.- Parameters:
delegate- the channel to forward I/O operations totimeout- the read/write timeouttimeoutUnit- the read/write timeout unit
-
BlockingByteChannel
public BlockingByteChannel(StreamChannel delegate, long readTimeout, TimeUnit readTimeoutUnit, long writeTimeout, TimeUnit writeTimeoutUnit) Construct a new instance.- Parameters:
delegate- the channel to forward I/O operations toreadTimeout- the read timeoutreadTimeoutUnit- the read timeout unitwriteTimeout- the write timeoutwriteTimeoutUnit- the write timeout unit
-
-
Method Details
-
setReadTimeout
Set the read timeout.- Parameters:
readTimeout- the read timeoutreadTimeoutUnit- the read timeout unit
-
setWriteTimeout
Set the write timeout.- Parameters:
writeTimeout- the write timeoutwriteTimeoutUnit- the write timeout unit
-
read
Perform a blocking, scattering read operation.- Specified by:
readin 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:
readin 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:
readin 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
-
write
Perform a blocking, gathering write operation.- Specified by:
writein interfaceGatheringByteChannel- Parameters:
srcs- the source buffersoffset- the offset into the destination buffer arraylength- the number of buffers to write from- Returns:
- the number of bytes actually written (will be greater than zero)
- Throws:
IOException- if an I/O error occurs
-
write
Perform a blocking, gathering write operation.- Specified by:
writein interfaceGatheringByteChannel- Parameters:
srcs- the source buffers- Returns:
- the number of bytes actually written (will be greater than zero)
- Throws:
IOException- if an I/O error occurs
-
write
Perform a blocking write operation.- Specified by:
writein interfaceWritableByteChannel- Parameters:
src- the source buffer- Returns:
- the number of bytes actually written (will be greater than zero)
- Throws:
IOException- if an I/O error occurs
-
isOpen
public boolean isOpen() -
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-