summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/NetworkInputStream.java
diff options
context:
space:
mode:
authorSergio Giro <sgiro@google.com>2016-02-01 10:41:58 +0000
committerSergio Giro <sgiro@google.com>2016-02-01 10:41:58 +0000
commit53b61f9fe9d58034fcc7021137e92460f91b70ce (patch)
tree90632062175928181977c1ab3ab59951bc1146c3 /bcprov/src/main/java/org/bouncycastle/crypto/tls/test/NetworkInputStream.java
parent3eebc2629986481f9fc77ab101c0c9b8ff2f2660 (diff)
downloadandroid_external_bouncycastle-53b61f9fe9d58034fcc7021137e92460f91b70ce.tar.gz
android_external_bouncycastle-53b61f9fe9d58034fcc7021137e92460f91b70ce.tar.bz2
android_external_bouncycastle-53b61f9fe9d58034fcc7021137e92460f91b70ce.zip
bouncycastle: Android tree with upstream code for version 1.52
Android tree as of 1af9aad12fedf1d93333e19f5ed0ab86f1cc4e2a Change-Id: I714fa0954a5d000cd88d1fb78b0b7fe28246d404
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/crypto/tls/test/NetworkInputStream.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/tls/test/NetworkInputStream.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/NetworkInputStream.java b/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/NetworkInputStream.java
new file mode 100644
index 0000000..e5f4770
--- /dev/null
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/tls/test/NetworkInputStream.java
@@ -0,0 +1,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");
+ }
+ }
+} \ No newline at end of file