Bad Code
// out is a FileOutputStream
final Base64.Encoder encoder = Base64.getMimeEncoder();
final OutputStream clob = encoder.wrap(out);
IOUtils.copy(in, clob, Charset.forName("UTF-8"));
// No close of clob Just went and kept writing to out
Good Code
// out is a FileOutputStream
final Base64.Encoder encoder = Base64.getMimeEncoder();
final OutputStream clob = encoder.wrap(
new CloseShieldOutputStream(out)); // Use nice Apache IO Wrapper that does // not chain close
IOUtils.copy(in, clob, Charset.forName("UTF-8"));
clob.close(); // this forces out the padding
No comments:
Post a Comment