blob: a11694b7154df3575934fb45f2b5cbbf50a2c99a (
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
|
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");
}
}
}
|