public class Base64OutputStream
extends java.io.FilterOutputStream
write
methods.
Base64 is the encoding format used by Multipurpose Internet Mail Extension (Mime) for transmitting non-text material over text-only communications channels. Base64 is based on a 65-character subset of US-ASCII, enabling 6 bits to be represented per printable character (see RFC 1521).
This class may be used for Base64 encoding some given data and writing it to a file, e.g.:
FileOutputStream fos = new FileOutputStream("test/base64.enc");
Base64OutputStream base64os = new Base64OutputStream(fos);
byte[] data = "Test Data to be Base64 encoded and written to a file".getBytes();
base64os.write(data);
base64os.flush();
base64os.close();
Base64InputStream| Constructor and Description |
|---|
Base64OutputStream(java.io.OutputStream out)
Creates a new Base64OutputStream to write Base64 encoded data (with line
breaks) to the specified underlying output stream.
|
Base64OutputStream(java.io.OutputStream out,
boolean includeLineBreaks)
Creates a new Base64OutputStream to write Base64 encoded data (with or
without line breaks) to the specified underlying output stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
countCRLFBytesWritten()
Returns the number of CRLF bytes (carriage return '\r' and line feed '\n')
that were written to the underlying output stream.
|
void |
flush()
Performs final processing and output to the output stream.
|
void |
write(byte[] in,
int inOff,
int inLen)
Base64 encodes the the specified number of bytes and writes them
to the underlying output stream.
|
void |
write(int b)
Base64 encodes the given byte and writes it to the underlying
output stream.
|
public Base64OutputStream(java.io.OutputStream out)
A line break (CRLF) is inserted after every 64th character; this style of Base64 encoding is used in Privacy Enhanced Mail (PEM).
out - - the underlying output stream.public Base64OutputStream(java.io.OutputStream out,
boolean includeLineBreaks)
If configured to do so via includeLineBreaks, a line break
(CRLF) is inserted after every 64th character; this style of Base64
encoding is used in Privacy Enhanced Mail (PEM).
out - - the underlying output stream.includeLineBreaks - indicates whether or not line breaks should be included in the
Base64 encoded valuepublic void write(int b)
throws java.io.IOException
write in class java.io.FilterOutputStreamb - the byte to be Base64 encoded.java.io.IOException - if an I/O error occurs.public void write(byte[] in,
int inOff,
int inLen)
throws java.io.IOException
The data to be processed is given in an input byte array. Beginning at
inOff, this method only encodes the first inLen
bytes and writes them to the underlying output stream.
write in class java.io.FilterOutputStreamin - the buffer containing the bytes to be Base64 encodedinOff - the offset indicating the start position within the input byte arrayinLen - the number of bytes to be processedjava.io.IOException - if an I/O error occurs.public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.FilterOutputStreamjava.io.IOException - If an error occurs.public int countCRLFBytesWritten()
For example, if one CRLF was written, this API will return 2 (each CRLF consists of two bytes).