public final class Base64OutputStream
extends java.io.FilterOutputStream
A Base64OutputStream encodes given bytes in Base64 characters and writes them in the given OutputStream.
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.
Base64
Constructor and Description |
---|
Base64OutputStream(java.io.OutputStream stream) |
Base64OutputStream(java.io.OutputStream stream,
int bufferSize) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Decodes and writes last given bytes
and finally flushes and closes the inner output stream.
|
void |
flush()
ONLY FLUSH THE INNER OUTPUT STREAM !
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
public Base64OutputStream(java.io.OutputStream stream)
stream
- public Base64OutputStream(java.io.OutputStream stream, int bufferSize)
stream
- bufferSize
- public void write(int b) throws java.io.IOException
write
in class java.io.FilterOutputStream
java.io.IOException
public void write(byte[] b) throws java.io.IOException
write
in class java.io.FilterOutputStream
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.FilterOutputStream
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.FilterOutputStream
java.io.IOException
FilterOutputStream.flush()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.FilterOutputStream
java.io.IOException
FilterOutputStream.close()