Class ListenableOutputStream<O extends OutputStream>
java.lang.Object
java.io.OutputStream
eu.cloudnetservice.utils.base.io.ListenableOutputStream<O>
- Type Parameters:
O- the type of the wrapped output stream.
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
An output stream implementation that holds a listener to call when the stream gets closed. The listener function can
for example be used to actually commit an action to the real underlying file system.
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionListenableOutputStream(O wrapped, @NonNull CheckedConsumer<O> closeListener) Constructs a new listenable output stream using the given stream as the target and the given close listener to call when the stream gets closed. -
Method Summary
Methods inherited from class OutputStream
nullOutputStream
-
Field Details
-
wrapped
-
closeListener
-
-
Constructor Details
-
ListenableOutputStream
public ListenableOutputStream(@NonNull O wrapped, @NonNull @NonNull CheckedConsumer<O> closeListener) Constructs a new listenable output stream using the given stream as the target and the given close listener to call when the stream gets closed.- Parameters:
wrapped- the stream to wrap and delegate all write calls to.closeListener- the close listener to call when this stream gets closed.- Throws:
NullPointerException- if the given wrapped stream or close listener is null.
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
Calls the given close listener and then closes the wrapped output stream, rethrowing any exception that was thrown by either of these two actions.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-