public void testInvalidInput() throws Exception {
String text = "blah blah yada yada";
byte[] b1 = text.getBytes("US-ASCII");
String pattern = "blah";
byte[] b2 = pattern.getBytes("US-ASCII");
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
assertEquals('b', inbuffer.read());
assertEquals('l', inbuffer.read());
try {
inbuffer.charAt(1);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.charAt(20);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, -1, 3);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, 1, 3);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, 2, -1);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf(b2, 2, 18);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
assertEquals(5, inbuffer.indexOf(b2, 2, 17));
try {
inbuffer.indexOf((byte)' ', -1, 3);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf((byte)' ', 1, 3);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf((byte)' ', 2, -1);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
try {
inbuffer.indexOf((byte)' ', 2, 18);
fail("IndexOutOfBoundsException should have been thrown");
} catch (IndexOutOfBoundsException expected) {
}
assertEquals(10, inbuffer.indexOf((byte)'y', 2, 17));
}