XNIO API 3.1.0.Beta1

org.xnio.channels
Class BlockingByteChannel

java.lang.Object
  extended by org.xnio.channels.BlockingByteChannel
All Implemented Interfaces:
Closeable, Flushable, 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.


Constructor Summary
BlockingByteChannel(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
 void close()
          
 void flush()
          
 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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingByteChannel

public BlockingByteChannel(StreamChannel delegate)
Construct a new instance.

Parameters:
delegate - the channel to forward I/O operations to

BlockingByteChannel

public BlockingByteChannel(StreamChannel delegate,
                           long timeout,
                           TimeUnit timeoutUnit)
Construct a new instance.

Parameters:
delegate - the channel to forward I/O operations to
timeout - the read/write timeout
timeoutUnit - 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 to
readTimeout - the read timeout
readTimeoutUnit - the read timeout unit
writeTimeout - the write timeout
writeTimeoutUnit - the write timeout unit
Method Detail

setReadTimeout

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

Parameters:
readTimeout - the read timeout
readTimeoutUnit - the read timeout unit

setWriteTimeout

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

Parameters:
writeTimeout - the write timeout
writeTimeoutUnit - the write timeout unit

read

public long read(ByteBuffer[] dsts,
                 int offset,
                 int length)
          throws IOException
Perform a blocking, scattering read operation.

Specified by:
read in interface ScatteringByteChannel
Parameters:
dsts - the destination buffers
offset - the offset into the destination buffer array
length - 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

public long read(ByteBuffer[] dsts)
          throws IOException
Perform a blocking, scattering read operation.

Specified by:
read in interface ScatteringByteChannel
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

public int read(ByteBuffer dst)
         throws IOException
Perform a blocking read operation.

Specified by:
read in interface ReadableByteChannel
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

public long write(ByteBuffer[] srcs,
                  int offset,
                  int length)
           throws IOException
Perform a blocking, gathering write operation.

Specified by:
write in interface GatheringByteChannel
Parameters:
srcs - the source buffers
offset - the offset into the destination buffer array
length - 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

public long write(ByteBuffer[] srcs)
           throws IOException
Perform a blocking, gathering write operation.

Specified by:
write in interface GatheringByteChannel
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

public int write(ByteBuffer src)
          throws IOException
Perform a blocking write operation.

Specified by:
write in interface WritableByteChannel
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()

Specified by:
isOpen in interface Channel

flush

public void flush()
           throws IOException

Specified by:
flush in interface Flushable
Throws:
IOException

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Specified by:
close in interface Channel
Throws:
IOException

XNIO API 3.1.0.Beta1

Copyright © 2010 JBoss, a division of Red Hat, Inc.