All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.tls.test.NetworkOutputStream Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.

There is a newer version: 1.78.1
Show newest version
package org.bouncycastle.crypto.tls.test;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Tracks and enforces close() calls, without closing the underlying OutputStream
 */
class NetworkOutputStream extends FilterOutputStream
{
    boolean closed = false;

    public NetworkOutputStream(OutputStream output)
    {
        super(output);
    }

    synchronized boolean isClosed()
    {
        return closed;
    }

    public synchronized void close() throws IOException
    {
        closed = true;
    }

    public void write(int b) throws IOException
    {
        checkNotClosed();
        out.write(b);
    }

    public void write(byte[] b) throws IOException
    {
        checkNotClosed();
        out.write(b);
    }

    public void write(byte[] b, int off, int len) throws IOException
    {
        checkNotClosed();
        out.write(b, off, len);
    }

    protected synchronized void checkNotClosed() throws IOException
    {
        if (closed)
        {
            throw new IOException("NetworkOutputStream closed");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy