Module 

Class BlockingReadableByteChannel

java.lang.Object
org.xnio.channels.BlockingReadableByteChannel
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel, ScatteringByteChannel

public class BlockingReadableByteChannel extends Object implements ScatteringByteChannel
A blocking wrapper for a StreamSourceChannel. 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 a ReadTimeoutException if the timeout expires without reading any data.
  • Constructor Details

    • 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, TimeUnit readTimeoutUnit)
      Construct a new instance.
      Parameters:
      delegate - the channel to forward I/O operations to
      readTimeout - the read timeout
      readTimeoutUnit - the read timeout unit
  • Method Details

    • setReadTimeout

      public void setReadTimeout(long readTimeout, TimeUnit readTimeoutUnit)
      Set the read timeout.
      Parameters:
      readTimeout - the read timeout
      readTimeoutUnit - the read 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
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface Channel
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      Throws:
      IOException