Class Base64OutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- cds.savot.binary.Base64OutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public final class Base64OutputStream extends java.io.FilterOutputStreamA 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
BufferedOutputStreamwith (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:
Base64
-
-
Constructor Summary
Constructors Constructor Description Base64OutputStream(java.io.OutputStream stream)Base64OutputStream(java.io.OutputStream stream, int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Decodes and writes last given bytes and finally flushes and closes the inner output stream.voidflush()ONLY FLUSH THE INNER OUTPUT STREAM !voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionONLY FLUSH THE INNER OUTPUT STREAM !- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.FilterOutputStream- Throws:
java.io.IOException- See Also:
FilterOutputStream.flush()
-
close
public void close() throws java.io.IOExceptionDecodes and writes last given bytes and finally flushes and closes the inner output stream.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.IOException- See Also:
FilterOutputStream.close()
-
-