Top Description Fields Constructors Methods
org.xnio.channels

public Class BlockingByteChannel

extends Object
implements ScatteringByteChannel, GatheringByteChannel, ByteChannel, Flushable
Class Inheritance
All Implemented Interfaces
java.io.Flushable, java.nio.channels.ByteChannel, java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ReadableByteChannel, java.nio.channels.GatheringByteChannel, java.nio.channels.ScatteringByteChannel
Static Imports
org.xnio._private.Messages.msg

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.

Field Summary

Modifier and TypeField and Description
private final StreamChannel
private volatile long
private volatile long

Constructor Summary

AccessConstructor and Description
public
BlockingByteChannel(final StreamChannel
the channel to forward I/O operations to
delegate
)

Construct a new instance.

public
BlockingByteChannel(final StreamChannel
the channel to forward I/O operations to
delegate
,
final long
the read/write timeout
timeout
,
final TimeUnit
the read/write timeout unit
timeoutUnit
)

Construct a new instance.

public
BlockingByteChannel(final StreamChannel
the channel to forward I/O operations to
delegate
,
final long
the read timeout
readTimeout
,
final TimeUnit
the read timeout unit
readTimeoutUnit
,
final long
the write timeout
writeTimeout
,
final TimeUnit
the write timeout unit
writeTimeoutUnit
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.nio.channels.Channel.close.

Closes this channel.

public void
flush()

Implements java.io.Flushable.flush.

Flushes this stream by writing any buffered output to the underlying stream.

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

public long

Returns:

the number of bytes actually read (will be greater than zero)
read
(final ByteBuffer[]
the destination buffers
dsts
,
final int
the offset into the destination buffer array
offset
,
final int
the number of buffers to read into
length
)

Implements java.nio.channels.ScatteringByteChannel.read.

Perform a blocking, scattering read operation.

public long

Returns:

the number of bytes actually read (will be greater than zero)
read
(final ByteBuffer[]
the destination buffers
dsts
)

Implements java.nio.channels.ScatteringByteChannel.read.

Perform a blocking, scattering read operation.

public int

Returns:

the number of bytes actually read (will be greater than zero)
read
(final ByteBuffer
the destination buffer
dst
)

Implements java.nio.channels.ReadableByteChannel.read.

Perform a blocking read operation.

public void
setReadTimeout(long
the read timeout
readTimeout
,
TimeUnit
the read timeout unit
readTimeoutUnit
)

Set the read timeout.

public void
setWriteTimeout(long
the write timeout
writeTimeout
,
TimeUnit
the write timeout unit
writeTimeoutUnit
)

Set the write timeout.

public long

Returns:

the number of bytes actually written (will be greater than zero)
write
(final ByteBuffer[]
the source buffers
srcs
,
final int
the offset into the destination buffer array
offset
,
final int
the number of buffers to write from
length
)

Implements java.nio.channels.GatheringByteChannel.write.

Perform a blocking, gathering write operation.

public long

Returns:

the number of bytes actually written (will be greater than zero)
write
(final ByteBuffer[]
the source buffers
srcs
)

Implements java.nio.channels.GatheringByteChannel.write.

Perform a blocking, gathering write operation.

public int

Returns:

the number of bytes actually written (will be greater than zero)
write
(final ByteBuffer
the source buffer
src
)

Implements java.nio.channels.WritableByteChannel.write.

Perform a blocking write operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final StreamChannel delegate
readTimeoutback to summary
private volatile long readTimeout
writeTimeoutback to summary
private volatile long writeTimeout

Constructor Detail

BlockingByteChannelback to summary
public BlockingByteChannel(final StreamChannel delegate)

Construct a new instance.

Parameters
delegate:StreamChannel

the channel to forward I/O operations to

BlockingByteChannelback to summary
public BlockingByteChannel(final StreamChannel delegate, final long timeout, final TimeUnit timeoutUnit)

Construct a new instance.

Parameters
delegate:StreamChannel

the channel to forward I/O operations to

timeout:long

the read/write timeout

timeoutUnit:TimeUnit

the read/write timeout unit

BlockingByteChannelback to summary
public BlockingByteChannel(final StreamChannel delegate, final long readTimeout, final TimeUnit readTimeoutUnit, final long writeTimeout, final TimeUnit writeTimeoutUnit)

Construct a new instance.

Parameters
delegate:StreamChannel

the channel to forward I/O operations to

readTimeout:long

the read timeout

readTimeoutUnit:TimeUnit

the read timeout unit

writeTimeout:long

the write timeout

writeTimeoutUnit:TimeUnit

the write timeout unit

Method Detail

closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

Implements java.io.Flushable.flush.

Doc from java.io.Flushable.flush.

Flushes this stream by writing any buffered output to the underlying stream.

Exceptions
IOException:
If an I/O error occurs
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

readback to summary
public long read(final ByteBuffer[] dsts, final int offset, final int length) throws IOException

Implements java.nio.channels.ScatteringByteChannel.read.

Perform a blocking, scattering read operation.

Parameters
dsts:ByteBuffer[]

the destination buffers

offset:int

the offset into the destination buffer array

length:int

the number of buffers to read into

Returns:long

the number of bytes actually read (will be greater than zero)

Exceptions
IOException:
if an I/O error occurs
readback to summary
public long read(final ByteBuffer[] dsts) throws IOException

Implements java.nio.channels.ScatteringByteChannel.read.

Perform a blocking, scattering read operation.

Parameters
dsts:ByteBuffer[]

the destination buffers

Returns:long

the number of bytes actually read (will be greater than zero)

Exceptions
IOException:
if an I/O error occurs
readback to summary
public int read(final ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Perform a blocking read operation.

Parameters
dst:ByteBuffer

the destination buffer

Returns:int

the number of bytes actually read (will be greater than zero)

Exceptions
IOException:
if an I/O error occurs
setReadTimeoutback to summary
public void setReadTimeout(long readTimeout, TimeUnit readTimeoutUnit)

Set the read timeout.

Parameters
readTimeout:long

the read timeout

readTimeoutUnit:TimeUnit

the read timeout unit

setWriteTimeoutback to summary
public void setWriteTimeout(long writeTimeout, TimeUnit writeTimeoutUnit)

Set the write timeout.

Parameters
writeTimeout:long

the write timeout

writeTimeoutUnit:TimeUnit

the write timeout unit

writeback to summary
public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException

Implements java.nio.channels.GatheringByteChannel.write.

Perform a blocking, gathering write operation.

Parameters
srcs:ByteBuffer[]

the source buffers

offset:int

the offset into the destination buffer array

length:int

the number of buffers to write from

Returns:long

the number of bytes actually written (will be greater than zero)

Exceptions
IOException:
if an I/O error occurs
writeback to summary
public long write(final ByteBuffer[] srcs) throws IOException

Implements java.nio.channels.GatheringByteChannel.write.

Perform a blocking, gathering write operation.

Parameters
srcs:ByteBuffer[]

the source buffers

Returns:long

the number of bytes actually written (will be greater than zero)

Exceptions
IOException:
if an I/O error occurs
writeback to summary
public int write(final ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Perform a blocking write operation.

Parameters
src:ByteBuffer

the source buffer

Returns:int

the number of bytes actually written (will be greater than zero)

Exceptions
IOException:
if an I/O error occurs