Class Base64OutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class Base64OutputStream extends FilterOutputStream

A Base64OutputStream encodes given bytes in Base64 characters and writes them in the given OutputStream.

The Base 64 encoding

  • According to the RFC-2045, valid Base64 characters are: A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,+,/.
  • Encoded data ARE splitted in lines of 76 characters, using the local line separator (System.getProperty("line.separator")).

Buffer

This stream is buffered. That means that encoded bytes sent to the inner output stream will be written when a given number of bytes are collected. By default the buffer size is: 8192.

Warning ! Actually the buffer is not managed in Base64OutputStream but in its inner output stream. At the initialization the given output stream is used to create a BufferedOutputStream with (N/3)*4 as buffer size (where N is the given buffer size). Indeed, with the Base64 encoding, the number of encoded bytes is always greater than the number of the corresponding decoded bytes: 3 bytes will be encoded by 4 characters encoded on 6 bits (which allows an alphabet of 2^6=64 characters, hence base64). Consequently: a buffer of N bytes in a BufferedOutputStream corresponds to a buffer of (N/3)*4 bytes in its inner output stream. So, when you set a buffer size of 8192 bytes at the creation of a Base64OutputStream, it is really implemented by a buffer of 10924 bytes.

Since:
09/2011
Author:
Gregory Mantelet
See Also: