Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NetworkInputStream.java « test « tls « crypto « bouncycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5f4770696d94efd2b3b032a1a218c16442bc6c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.bouncycastle.crypto.tls.test;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Tracks and enforces close() calls, without closing the underlying InputStream
 */
class NetworkInputStream extends FilterInputStream
{
    boolean closed = false;

    public NetworkInputStream(InputStream input)
    {
        super(input);
    }

    synchronized boolean isClosed()
    {
        return closed;
    }

    public int available() throws IOException
    {
        checkNotClosed();
        return in.available();
    }

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

    public int read() throws IOException
    {
        checkNotClosed();
        return in.read();
    }

    public int read(byte[] b) throws IOException
    {
        checkNotClosed();
        return in.read(b);
    }

    public int read(byte[] b, int off, int len) throws IOException
    {
        checkNotClosed();
        return in.read(b, off, len);
    }

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