Class BlockingWritableByteChannel

java.lang.Object
org.xnio.channels.BlockingWritableByteChannel
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, Channel, GatheringByteChannel, WritableByteChannel

public class BlockingWritableByteChannel extends Object implements GatheringByteChannel, Flushable
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 Details

    • BlockingWritableByteChannel

      public BlockingWritableByteChannel(StreamSinkChannel delegate)
      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 to
      writeTimeout - the write timeout
      writeTimeoutUnit - the write timeout unit
  • Method Details

    • setWriteTimeout

      public void setWriteTimeout(long writeTimeout, TimeUnit writeTimeoutUnit)
      Set the write timeout.
      Parameters:
      writeTimeout - the write timeout
      writeTimeoutUnit - the write timeout unit
    • 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 AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      Throws:
      IOException