title: How to Base64 encode a Java object using org.apache.commons.codec.binary.base64?
body: <p>I've been trying to do an object serialization and Base64 encode the result. It works with Sun's lib:</p>
  
  <pre><code>Bean01 bean01 = new Bean01();
  bean01.setDefaultValues();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  new ObjectOutputStream( baos ).writeObject( bean01 );
  System.out.println(Base64.encode(baos.toByteArray()));
  </code></pre>
  
  <p>This works fine. However, I would like to do the same using org.apache.commons.codec.binary.base64, but this does not return the same string:</p>
  
  <p><code>System.out.println(org.apache.commons.codec.binary.Base64.encodeBase64(baos.toByteArray()));</code></p>
  
  <p>What would be the correct way to achieve the correct Base64 encoding of a byteArray using Apache's encoder?</p>