JCLOUDS-912: Implement RandomInputStream.close

Prevent reading closed RandomInputStream.
This commit is contained in:
Andrew Gaul 2015-05-25 21:53:52 -07:00
parent 9532e7ccf4
commit 1a64a1f0fe
1 changed files with 11 additions and 1 deletions

View File

@ -59,13 +59,17 @@ public class TestUtils {
private static class RandomInputStream extends InputStream {
private final Random random;
private boolean closed = false;
RandomInputStream(long seed) {
this.random = new Random(seed);
}
@Override
public synchronized int read() {
public synchronized int read() throws IOException {
if (closed) {
throw new IOException("Stream already closed");
}
return (byte) random.nextInt();
}
@ -81,5 +85,11 @@ public class TestUtils {
}
return len;
}
@Override
public void close() throws IOException {
super.close();
closed = true;
}
}
}