@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); }
static void pipe( final InputStream in, final OutputStream out, final byte[] buffer, int copyLength) throws IOException { while (copyLength > 0) { int maxCopy = Math.min(buffer.length, copyLength); readFully(in, buffer, 0, maxCopy); out.write(buffer, 0, maxCopy); copyLength -= maxCopy; } }
BsPatch { static void pipe( final InputStream in, final OutputStream out, final byte[] buffer, int copyLength) throws IOException { while (copyLength > 0) { int maxCopy = Math.min(buffer.length, copyLength); readFully(in, buffer, 0, maxCopy); out.write(buffer, 0, maxCopy); copyLength -= maxCopy; } } }
BsPatch { static void pipe( final InputStream in, final OutputStream out, final byte[] buffer, int copyLength) throws IOException { while (copyLength > 0) { int maxCopy = Math.min(buffer.length, copyLength); readFully(in, buffer, 0, maxCopy); out.write(buffer, 0, maxCopy); copyLength -= maxCopy; } }  }
BsPatch { static void pipe( final InputStream in, final OutputStream out, final byte[] buffer, int copyLength) throws IOException { while (copyLength > 0) { int maxCopy = Math.min(buffer.length, copyLength); readFully(in, buffer, 0, maxCopy); out.write(buffer, 0, maxCopy); copyLength -= maxCopy; } }  static void applyPatch(
      RandomAccessFile oldData, OutputStream newData, InputStream patchData); }
BsPatch { static void pipe( final InputStream in, final OutputStream out, final byte[] buffer, int copyLength) throws IOException { while (copyLength > 0) { int maxCopy = Math.min(buffer.length, copyLength); readFully(in, buffer, 0, maxCopy); out.write(buffer, 0, maxCopy); copyLength -= maxCopy; } }  static void applyPatch(
      RandomAccessFile oldData, OutputStream newData, InputStream patchData);  }