Class ListenableOutputStream<O extends OutputStream>

java.lang.Object
java.io.OutputStream
eu.cloudnetservice.common.io.ListenableOutputStream<O>
Type Parameters:
O - the type of the wrapped output stream.
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class ListenableOutputStream<O extends OutputStream> extends OutputStream
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
    Modifier and Type
    Field
    Description
    private final io.vavr.CheckedConsumer<O>
     
    private final O
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ListenableOutputStream(O wrapped, @NonNull io.vavr.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

    Modifier and Type
    Method
    Description
    void
    Calls the given close listener and then closes the wrapped output stream, rethrowing any exception that was thrown by either of these two actions.
    void
    void
    write(byte @NonNull [] b)
    void
    write(byte @NonNull [] b, int off, int len)
    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