@Test
public void testPipe() throws IOException {

  final String inputString = "this is a sample string to read";
  final byte[] input = inputString.getBytes("US-ASCII");
  final ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
  final byte[] buffer = new byte[5];
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  BsPatch.pipe(inputStream, outputStream, buffer, 0);
  int actualLength = outputStream.toByteArray().length;
  Assert.assertEquals(0, actualLength);
  inputStream.reset();
  BsPatch.pipe(inputStream, outputStream, buffer, 1);
  actualLength = outputStream.toByteArray().length;
  Assert.assertEquals(1, actualLength);
  byte actualByte = outputStream.toByteArray()[0];
  Assert.assertEquals((byte) 't', actualByte);
  outputStream = new ByteArrayOutputStream();
  inputStream.reset();
  BsPatch.pipe(inputStream, outputStream, buffer, 5);
  actualLength = outputStream.toByteArray().length;
  Assert.assertEquals(5, actualLength);
  String actualOutput = outputStream.toString();
  String expectedOutput = inputString.substring(0, 5);
  Assert.assertEquals(expectedOutput, actualOutput);
  outputStream = new ByteArrayOutputStream();
  inputStream.reset();
  BsPatch.pipe(inputStream, outputStream, buffer, input.length);
  actualLength = outputStream.toByteArray().length;
  Assert.assertEquals(input.length, actualLength);
  expectedOutput = outputStream.toString();
  Assert.assertEquals(inputString, expectedOutput);
}