Class Base64OutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
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:
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorsConstructorDescriptionBase64OutputStream
(OutputStream stream) Base64OutputStream
(OutputStream stream, int bufferSize) -
Method Summary
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
Base64OutputStream
- Parameters:
stream
-
-
Base64OutputStream
- Parameters:
stream
-bufferSize
-
-
-
Method Details
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
flush
ONLY FLUSH THE INNER OUTPUT STREAM !- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterOutputStream
- Throws:
IOException
- See Also:
-
close
Decodes and writes last given bytes and finally flushes and closes the inner output stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
- See Also:
-