MergeBytesInputStream extends java.io.FilterInputStream { @Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); } MergeBytesInputStream(java.io.InputStream inputStream);  MergeBytesInputStream(java.io.InputStream inputStream, int beginFrame, int endFrame, int escape, Merger merger); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override int read(); static final int BEGIN_FRAME; static final int END_FRAME; static final int END_OF_FILE; }
@Test(timeout = TIMEOUT) public void testSingleByteRead() throws IOException { InputStream is = new MergeBytesInputStream(new ByteArrayInputStream(TEST_DATA)); assertEquals(0x44, is.read()); assertEquals(MergeBytesInputStream.BEGIN_FRAME, is.read()); assertEquals(0x55, is.read()); assertEquals(0x85, is.read()); assertEquals(0x00, is.read()); assertEquals(0x80, is.read()); is.close(); }
@Test(timeout = TIMEOUT) public void testReadArray() throws IOException { InputStream is = new MergeBytesInputStream(new ByteArrayInputStream(TEST_DATA)); byte out[] = new byte[50]; int n = is.read(out, 0, 2); assertTrue(MergeBytesInputStream.BEGIN_FRAME == n); n = is.read(out, 0, 5); assertEquals(4, n); byte[] expected = new byte[] { 0x55, (byte) 0x85, 0x00, (byte) 0x80 }; assertArrayEquals(expected, Arrays.copyOfRange(out, 0, 4)); n = is.read(out, 0, 1); assertEquals(1, n); assertArrayEquals(new byte[] { 0x77 }, Arrays.copyOfRange(out, 0, 1)); is.close(); }