StreamHelper { public static String base64Encode(MessageDigest messageDigest) { return toBase64(messageDigest.digest()); }  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 base64Encode() throws IOException { DigestOutputStream digestOutputStream = StreamHelper.createMd5MessageOutputStream(new StreamHelper.NullOutputStream()); assertEquals( "1B2M2Y8AsgTpgAmY7PhCfg==", StreamHelper.base64Encode(digestOutputStream.getMessageDigest())); digestOutputStream.write(TEST_STR.getBytes()); assertEquals( "w/zT12GS5AB9+0lsymfhOw==", StreamHelper.base64Encode(digestOutputStream.getMessageDigest())); assertEquals( "1B2M2Y8AsgTpgAmY7PhCfg==", StreamHelper.base64Encode(digestOutputStream.getMessageDigest())); }