StreamHelper { public static long copy(InputStream in, OutputStream out) throws IOException { try { byte[] buffer = new byte[BUFFER_SIZE]; long bytesWritten = 0; int bytesRead = 0; while (-1 != (bytesRead = in.read(buffer))) { out.write(buffer, 0, bytesRead); bytesWritten += bytesRead; } return bytesWritten; } finally { StreamUtils.closeQuietly(in); } }  static long copy(InputStream in, OutputStream out); static String base64EncodeMd5Digest(byte[] buffer); static DigestOutputStream createMd5MessageOutputStream(OutputStream stream); static String base64Encode(MessageDigest messageDigest);  }
@Test public void copy() throws Exception { String testString = Strings.repeat(TEST_STR, 10000); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamHelper.copy(new ByteArrayInputStream(testString.getBytes()), baos); assertEquals(testString, new String(baos.toByteArray())); }