@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Test(expected=IndexOutOfBoundsException.class) public void testReadArrayOffsetLength_LengthTooLarge() throws Exception { in.read(bs, 2, 3); } @Test public void testReadArrayOffsetLength_HitEndOfStream()
@Test public void testReadArrayOffsetLength_AtEndOfStream() throws Exception { for (int i = 0; i < DATA_BYTES.length; i++) { in.read(); } byte[] expected = Arrays.copyOf(bs, bs.length); assertEquals(-1, in.read(bs, 2, 2)); assertArrayEquals(expected, bs); } @Test public void testReadArrayOffsetLength_0Length() throws Exception {
@Test public void testReadArrayOffsetLength_HitEndOfStream() throws Exception { for (int i = 0; i < DATA_BYTES.length - 1; i++) { in.read(); } assertEquals(1, in.read(bs, 2, 2)); byte[] expected = new byte[] { (byte) 1, (byte) 2, DATA_BYTES[DATA_BYTES.length - 1], (byte) 4 }; assertArrayEquals(expected, bs); } @Test public void testReadArrayOffsetLength_AtEndOfStream()
@Test public void testSkip2() throws Exception { for (int i = 0; i < DATA_BYTES.length / 2; i++) { in.read(); } long skipAmount = DATA_BYTES.length / 4; assertEquals(skipAmount, in.skip(skipAmount)); int idx = DATA_BYTES.length / 2 + (int) skipAmount; assertEquals(DATA_BYTES[idx++], in.read()); assertEquals(DATA_BYTES[idx++], in.read()); } @Test public void testNegativeSkip() throws Exception {
@Test public void testReadArrayOffsetLength_0Length() throws Exception { byte[] expected = Arrays.copyOf(bs, bs.length); assertEquals(0, in.read(bs, 2, 0)); assertArrayEquals(expected, bs); } @Test public void testReadArray() throws Exception {
@Test public void testReadArray() throws Exception { byte[] expected = Arrays.copyOf(DATA_BYTES, 4); assertEquals(4, in.read(bs)); assertArrayEquals(expected, bs); }
@Test public void testReadArrayOffsetLength() throws Exception { assertEquals(1, in.read(bs, 2, 1)); byte[] expected = new byte[] { (byte) 1, (byte) 2, DATA_BYTES[0], (byte) 4 }; assertArrayEquals(expected, bs); } @Test(expected=IndexOutOfBoundsException.class)
@Test public void testAvailable() throws Exception { for (int i = DATA_BYTES.length; i > 0; i--) { assertEquals(i, in.available()); in.read(); } assertEquals(0, in.available()); } }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }