Module 

Class Conduits


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

      Constructors 
      Constructor Description
      Conduits()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long drain​(StreamSourceConduit conduit, long count)
      Attempt to drain the given number of bytes from the stream source conduit.
      static boolean sendFinalBasic​(MessageSinkConduit conduit, java.nio.ByteBuffer src)
      Writes a message to the conduit, and terminates writes if the send was successfully.
      static boolean sendFinalBasic​(MessageSinkConduit conduit, java.nio.ByteBuffer[] srcs, int offset, int length)
      Writes a message to the conduit, and terminates writes if the send was successfully.
      static long transfer​(java.nio.channels.ReadableByteChannel source, long count, java.nio.ByteBuffer throughBuffer, StreamSinkConduit sink)
      Platform-independent channel-to-channel transfer method.
      static long transfer​(StreamSourceConduit source, long count, java.nio.ByteBuffer throughBuffer, java.nio.channels.WritableByteChannel sink)
      Platform-independent channel-to-channel transfer method.
      static int writeFinalBasic​(StreamSinkConduit conduit, java.nio.ByteBuffer src)
      Writes the buffer to the conduit, and terminates writes if all the data is written
      static long writeFinalBasic​(StreamSinkConduit conduit, java.nio.ByteBuffer[] srcs, int offset, int length)
      Writes the buffer to the conduit, and terminates writes if all the data is written
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Conduits

        public Conduits()
    • Method Detail

      • transfer

        public static long transfer​(StreamSourceConduit source,
                                    long count,
                                    java.nio.ByteBuffer throughBuffer,
                                    java.nio.channels.WritableByteChannel sink)
                             throws java.io.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:
        java.io.IOException - if an I/O error occurs during the transfer of bytes
      • transfer

        public static long transfer​(java.nio.channels.ReadableByteChannel source,
                                    long count,
                                    java.nio.ByteBuffer throughBuffer,
                                    StreamSinkConduit sink)
                             throws java.io.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:
        java.io.IOException - if an I/O error occurs during the transfer of bytes
      • writeFinalBasic

        public static int writeFinalBasic​(StreamSinkConduit conduit,
                                          java.nio.ByteBuffer src)
                                   throws java.io.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:
        java.io.IOException
      • writeFinalBasic

        public static long writeFinalBasic​(StreamSinkConduit conduit,
                                           java.nio.ByteBuffer[] srcs,
                                           int offset,
                                           int length)
                                    throws java.io.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:
        java.io.IOException
      • sendFinalBasic

        public static boolean sendFinalBasic​(MessageSinkConduit conduit,
                                             java.nio.ByteBuffer src)
                                      throws java.io.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:
        java.io.IOException
      • sendFinalBasic

        public static boolean sendFinalBasic​(MessageSinkConduit conduit,
                                             java.nio.ByteBuffer[] srcs,
                                             int offset,
                                             int length)
                                      throws java.io.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:
        java.io.IOException
      • drain

        public static long drain​(StreamSourceConduit conduit,
                                 long count)
                          throws java.io.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:
        java.io.IOException - if an error occurs