DatagramReader { public DatagramReader createRangeReader(int count) { return new DatagramReader(createRangeInputStream(count)); } DatagramReader(final byte[] byteArray);  DatagramReader(final byte[] byteArray, boolean copy);  DatagramReader(final byte[] byteArray, int offset, int length);  DatagramReader(final ByteArrayInputStream byteStream); void mark(); void reset(); void close(); long readLong(final int numBits); int read(final int numBits); byte[] readBytes(final int count); byte readNextByte(); byte[] readBytesLeft(); boolean bytesAvailable(); boolean bytesAvailable(final int expectedBytes); int bitsLeft(); DatagramReader createRangeReader(int count); ByteArrayInputStream createRangeInputStream(int count);  }
@Test public void testCreateRangeReader() { givenABuffer(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }); assertThat(reader.readNextByte(), is((byte)0x01)); DatagramReader rangeReader = reader.createRangeReader(4); assertThat(reader.readNextByte(), is((byte)0x06)); assertThat(reader.bytesAvailable(), is(false)); assertThat(rangeReader.readNextByte(), is((byte)0x02)); assertThat(rangeReader.readNextByte(), is((byte)0x03)); assertThat(rangeReader.readNextByte(), is((byte)0x04)); assertThat(rangeReader.readNextByte(), is((byte)0x05)); assertThat(rangeReader.bytesAvailable(), is(false)); }