class ReleasableOutputStream extends OutputStream {

    @Override
    public void flush() throws IOException {
        try {
            delegate.flush();
        } catch (IOException e) {
            safeClose();
            isClosed = true;
        }
    }

    public  ReleasableOutputStream(OutputStream delegate, Runnable onClose);

}