@Test
public void testRead_WithPartialBuffer() throws IOException {

  int bytesLeft = testData.length;
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  byte[] buffer = new byte[10];
  while (bytesLeft > 0) {
    int numRead = stream.read(buffer, 0, 2); // At most 2 bytes of the buffer can be used
    if (numRead > 0) {
      bytesLeft -= numRead;
      out.write(buffer, 0, numRead);
    }
  }
  Assert.assertEquals(-1, stream.read());
  Assert.assertArrayEquals(testData, out.toByteArray());
}