Package io.deephaven.util.channel
Class CompletableOutputStream
java.lang.Object
java.io.OutputStream
io.deephaven.util.channel.CompletableOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
complete()
Flush all buffered data and save all written data to the underlying storage.abstract void
done()
Flush all buffered data to the underlying storage.abstract void
rollback()
Try to roll back any data written to the underlying storage, reverting back to the original state before opening this stream.Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write, write, write
-
Constructor Details
-
CompletableOutputStream
public CompletableOutputStream()
-
-
Method Details
-
done
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 anIOException
.- Throws:
IOException
-
complete
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 anIOException
.- Throws:
IOException
-
rollback
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
-