Class FastContentOutputStream

  • All Implemented Interfaces:
    com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean>, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.util.concurrent.Future<java.lang.Boolean>

    public class FastContentOutputStream
    extends java.io.OutputStream
    implements com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean>

    This class extends the AbstractContentOutputStream, and forwards all write() and close() calls to a FastContentWriter. This means that once OutputStream.close() has been called, the asynchronous completion of all pending operations can be awaited using the ListenableFuture interface of this class. 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 OutputStream.close() has been called.

    Author:
    Simon Thoresen Hult
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BUFFERSIZE  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(java.lang.Runnable listener, java.util.concurrent.Executor executor)  
      boolean cancel​(boolean mayInterruptIfRunning)  
      void close()  
      protected void doClose()  
      protected void doFlush​(java.nio.ByteBuffer buf)  
      void flush()  
      java.lang.Boolean get()  
      java.lang.Boolean get​(long timeout, java.util.concurrent.TimeUnit unit)  
      boolean isCancelled()  
      boolean isDone()  
      void write​(byte[] buffer)  
      void write​(byte[] buffer, int offset, int length)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • FastContentOutputStream

        public FastContentOutputStream​(ContentChannel out)

        Constructs a new FastContentOutputStream that writes into the given ContentChannel.

        Parameters:
        out - The ContentChannel to write the stream into.
      • FastContentOutputStream

        public FastContentOutputStream​(FastContentWriter out)

        Constructs a new FastContentOutputStream that writes into the given FastContentWriter.

        Parameters:
        out - The ContentWriter to write the stream into.
    • Method Detail

      • doFlush

        protected void doFlush​(java.nio.ByteBuffer buf)
      • doClose

        protected void doClose()
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<java.lang.Boolean>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<java.lang.Boolean>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<java.lang.Boolean>
      • get

        public java.lang.Boolean get()
                              throws java.lang.InterruptedException,
                                     java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<java.lang.Boolean>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public java.lang.Boolean get​(long timeout,
                                     java.util.concurrent.TimeUnit unit)
                              throws java.lang.InterruptedException,
                                     java.util.concurrent.ExecutionException,
                                     java.util.concurrent.TimeoutException
        Specified by:
        get in interface java.util.concurrent.Future<java.lang.Boolean>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • addListener

        public void addListener​(java.lang.Runnable listener,
                                java.util.concurrent.Executor executor)
        Specified by:
        addListener in interface com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean>
      • write

        public final void write​(int b)
        Specified by:
        write in class java.io.OutputStream
      • write

        public final void write​(byte[] buffer,
                                int offset,
                                int length)
        Overrides:
        write in class java.io.OutputStream
      • write

        public final void write​(byte[] buffer)
        Overrides:
        write in class java.io.OutputStream
      • flush

        public final void flush()
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
      • close

        public final void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream