mirror of https://github.com/apache/jclouds.git
JCLOUDS-912: Implement RandomInputStream.close
Prevent reading closed RandomInputStream.
This commit is contained in:
parent
9532e7ccf4
commit
1a64a1f0fe
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue