* This tests that the EofFilterInputStream restores the traditional
* expected behavior when reading while at EOF on an AutoClosed stream.
*/
public void testAutoCloseProtection() throws IOException {
InputStream in =
new EofFilterInputStream(new AutoCloseInputStream(
new ClosableInputStream(new ByteArrayInputStream(bytes))));
int rtn = in.read(buffer);
assertEquals(3, rtn);
// We should keep hitting EOF now.
rtn = in.read(buffer);
assertEquals(-1, rtn);
rtn = in.read(buffer, 0, buffer.length);
assertEquals(-1, rtn);
rtn = in.read();
assertEquals(-1, rtn);
rtn = in.read(buffer);
assertEquals(-1, rtn);
rtn = in.read(buffer, 0, buffer.length);
assertEquals(-1, rtn);
rtn = in.read();
assertEquals(-1, rtn);
// Now explicitly close the stream. Further access should be denied.
in.close();
try {
rtn = in.read(buffer);
fail("IOException was not thrown on access to closed stream.");
} catch (IOException ioe) {
assertEquals(errorMsg, ioe.getMessage());
}
}