Class Conduits

java.lang.Object
org.xnio.conduits.Conduits

public final class Conduits extends Object
General utility methods for manipulating conduits.
Author:
David M. Lloyd
  • Constructor Details

    • Conduits

      public Conduits()
  • Method Details

    • transfer

      public static long transfer(StreamSourceConduit source, long count, ByteBuffer throughBuffer, WritableByteChannel sink) throws IOException
      Platform-independent channel-to-channel transfer method. Uses regular read and write operations to move bytes from the source channel to the sink channel. After this call, the throughBuffer should be checked for remaining bytes; if there are any, they should be written to the sink channel before proceeding. This method may be used with NIO channels, XNIO channels, or a combination of the two.

      If either or both of the given channels are blocking channels, then this method may block.

      Parameters:
      source - the source channel to read bytes from
      count - the number of bytes to transfer (must be >= 0L)
      throughBuffer - the buffer to transfer through (must not be null)
      sink - the sink channel to write bytes to
      Returns:
      the number of bytes actually transferred (possibly 0)
      Throws:
      IOException - if an I/O error occurs during the transfer of bytes
    • transfer

      public static long transfer(ReadableByteChannel source, long count, ByteBuffer throughBuffer, StreamSinkConduit sink) throws IOException
      Platform-independent channel-to-channel transfer method. Uses regular read and write operations to move bytes from the source channel to the sink channel. After this call, the throughBuffer should be checked for remaining bytes; if there are any, they should be written to the sink channel before proceeding. This method may be used with NIO channels, XNIO channels, or a combination of the two.

      If either or both of the given channels are blocking channels, then this method may block.

      Parameters:
      source - the source channel to read bytes from
      count - the number of bytes to transfer (must be >= 0L)
      throughBuffer - the buffer to transfer through (must not be null)
      sink - the sink channel to write bytes to
      Returns:
      the number of bytes actually transferred (possibly 0)
      Throws:
      IOException - if an I/O error occurs during the transfer of bytes
    • writeFinalBasic

      public static int writeFinalBasic(StreamSinkConduit conduit, ByteBuffer src) throws IOException
      Writes the buffer to the conduit, and terminates writes if all the data is written
      Parameters:
      conduit - The conduit to write to
      src - The data to write
      Returns:
      The number of bytes written
      Throws:
      IOException
    • writeFinalBasic

      public static long writeFinalBasic(StreamSinkConduit conduit, ByteBuffer[] srcs, int offset, int length) throws IOException
      Writes the buffer to the conduit, and terminates writes if all the data is written
      Parameters:
      conduit - The conduit to write to
      srcs - The data to write
      offset - The offset into the data array
      length - The number of buffers to write
      Returns:
      The number of bytes written
      Throws:
      IOException
    • sendFinalBasic

      public static boolean sendFinalBasic(MessageSinkConduit conduit, ByteBuffer src) throws IOException
      Writes a message to the conduit, and terminates writes if the send was successfully.
      Parameters:
      conduit - The conduit
      src - The message buffer
      Returns:
      true if the message was sent successfully
      Throws:
      IOException
    • sendFinalBasic

      public static boolean sendFinalBasic(MessageSinkConduit conduit, ByteBuffer[] srcs, int offset, int length) throws IOException
      Writes a message to the conduit, and terminates writes if the send was successfully.
      Parameters:
      conduit - The conduit
      srcs - The message buffers
      offset - The offset in the message buffers
      length - The number of buffers to send
      Returns:
      true if the message was sent successfully
      Throws:
      IOException
    • drain

      public static long drain(StreamSourceConduit conduit, long count) throws IOException
      Attempt to drain the given number of bytes from the stream source conduit.
      Parameters:
      conduit - the conduit to drain
      count - the number of bytes
      Returns:
      the number of bytes drained, 0 if reading the conduit would block, or -1 if the EOF was reached
      Throws:
      IOException - if an error occurs