Class CompletableOutputStream

java.lang.Object
java.io.OutputStream
io.deephaven.util.channel.CompletableOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public abstract class CompletableOutputStream extends OutputStream
An OutputStream that can be marked as done, completed, or rolled back.

The done() method is used to flush all buffered data to the underlying storage, complete() to finalize the write operation, and rollback() to cancel the write. Closing this output stream without calling complete will not flush data to the underlying storage.

One usage pattern can be like this:

 try (final CompletableOutputStream outputStream = CreateCompletableOutputStream()) {
     try {
         IOUtils.copy(inputStream, outputStream);
         outputStream.done(); // Optional; use this to flush buffered data without completing the stream
         outputStream.complete();
     } catch (IOException e) {
         outputStream.rollback();
     }
 }
 
  • Constructor Details

    • CompletableOutputStream

      public CompletableOutputStream()
  • Method Details

    • done

      public abstract void done() throws IOException
      Flush all buffered data to the underlying storage. This is optional and should be called after the user is done writing to the output stream. All writes to the output stream after calling this method will lead to an IOException.
      Throws:
      IOException
    • complete

      public abstract void complete() throws IOException
      Flush all buffered data and save all written data to the underlying storage. This method should be called after the user is done writing to the output stream. All writes to the output stream after calling this method will lead to an IOException.
      Throws:
      IOException
    • rollback

      public abstract void rollback() throws IOException
      Try to roll back any data written to the underlying storage, reverting back to the original state before opening this stream. This is an optional operation, as some implementations may not be able to support it.
      Throws:
      IOException