title: Base64 encoding not working
body: <p>I'm using the following code to encode a <code>java.awt.Image</code> in Base64:</p>
  
  <pre><code>private String asBase64(Image image) throws IOException {
      BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
              image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      ImageIO.write(bufferedImage, "PNG", out);
      byte[] bytes = out.toByteArray();
  
      return Base64.encodeBytes(bytes);
  }
  </code></pre>
  
  <p>But the returned String is somehow wrong: It seems to be too small (only 308 chars on a 20KB-file) and contains a big amount of repetitive characters in the middle (~200 <code>A</code> chars).</p>
  
  <p>I did some debugging and found out that <code>bufferedImage</code> at least has correct dimensions, but <code>out</code> only contains 308 bytes after executing <code>ImageIO.write(...)</code>. This number increases with bigger images, but the characters keep being repetitive and too few.</p>
  
  <p>Am I missing something?</p>