@Test public void testRead() throws IOException { out.write(new byte[] {1, 2, 3, 4}); BinaryReader reader = getReader(); assertEquals(1, reader.read()); byte[] tmp = new byte[10]; assertEquals(3, reader.read(tmp, 2, 8)); assertArrayEquals(new byte[] {0, 0, 2, 3, 4, 0, 0, 0, 0, 0}, tmp); try { reader.read(tmp, 5, 6); } catch (IllegalArgumentException e) { assertEquals("Illegal arguments for read: byte[10], off:5, len:6", e.getMessage()); } }
@Test public void testBytes() throws IOException { byte[] bytes = new byte[] {0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // test writing and reading bytes. writer.write(bytes); BinaryReader reader = getReader(); byte[] read = new byte[bytes.length]; reader.read(read); assertArrayEquals(bytes, read); }