Package org.xnio.channels
Class BlockingWritableByteChannel
java.lang.Object
org.xnio.channels.BlockingWritableByteChannel
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,Channel
,GatheringByteChannel
,WritableByteChannel
A blocking wrapper for a
StreamChannel
. Write operations will block until some data may be transferred.
Once any amount of data is written, the operation will return. If a write timeout is specified, then the write methods
will throw a WriteTimeoutException
if the timeout expires without writing any data.-
Constructor Summary
ConstructorsConstructorDescriptionBlockingWritableByteChannel
(StreamSinkChannel delegate) Construct a new instance.BlockingWritableByteChannel
(StreamSinkChannel delegate, long writeTimeout, TimeUnit writeTimeoutUnit) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
boolean
isOpen()
void
setWriteTimeout
(long writeTimeout, TimeUnit writeTimeoutUnit) Set the write timeout.int
write
(ByteBuffer src) Perform a blocking write operation.long
write
(ByteBuffer[] srcs) Perform a blocking, gathering write operation.long
write
(ByteBuffer[] srcs, int offset, int length) Perform a blocking, gathering write operation.
-
Constructor Details
-
BlockingWritableByteChannel
Construct a new instance.- Parameters:
delegate
- the channel to forward I/O operations to
-
BlockingWritableByteChannel
public BlockingWritableByteChannel(StreamSinkChannel delegate, long writeTimeout, TimeUnit writeTimeoutUnit) Construct a new instance.- Parameters:
delegate
- the channel to forward I/O operations towriteTimeout
- the write timeoutwriteTimeoutUnit
- the write timeout unit
-
-
Method Details
-
setWriteTimeout
Set the write timeout.- Parameters:
writeTimeout
- the write timeoutwriteTimeoutUnit
- the write timeout unit
-
write
Perform a blocking, gathering write operation.- Specified by:
write
in 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:
write
in 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:
write
in 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:
flush
in interfaceFlushable
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-