Class FastContentWriter

  • All Implemented Interfaces:
    AutoCloseable, CompletionStage<Boolean>, Future<Boolean>

    public class FastContentWriter
    extends CompletableFuture<Boolean>
    implements AutoCloseable

    This class provides a non-blocking, awaitable write-interface to a ContentChannel. The ListenableFuture<Boolean> interface can be used to await the asynchronous completion of all pending operations. Any asynchronous failure will be rethrown when calling either of the get() methods on this class.

    Please notice that the Future implementation of this class will NEVER complete unless close() has been called; please use try-with-resources to ensure that close() is called.

    Author:
    Simon Thoresen Hult
    • Constructor Detail

      • FastContentWriter

        public FastContentWriter​(ContentChannel out)

        Creates a new FastContentWriter that encapsulates a given ContentChannel.

        Parameters:
        out - The ContentChannel to encapsulate.
        Throws:
        NullPointerException - If the content argument is null.
    • Method Detail

      • write

        public void write​(String str)

        This is a convenience method to convert the given string to a ByteBuffer of UTF8 bytes, and then passing that to write(ByteBuffer).

        Parameters:
        str - The string to write.
      • write

        public void write​(byte[] buf)

        This is a convenience method to convert the given byte array into a ByteBuffer object, and then passing that to write(java.nio.ByteBuffer).

        Parameters:
        buf - The bytes to write.
      • write

        public void write​(byte[] buf,
                          int offset,
                          int length)

        This is a convenience method to convert a subarray of the given byte array into a ByteBuffer object, and then passing that to write(java.nio.ByteBuffer).

        Parameters:
        buf - The bytes to write.
        offset - The offset of the subarray to be used.
        length - The length of the subarray to be used.
      • addListener

        public void addListener​(Runnable listener,
                                Executor executor)