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 or RFC 2045).
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();
Using the constructor Base64OutputStream(OutputStream, byte[]), the
application can specify a different line-break than the default, which is
carriage return (0xD) plus line feed (0xA). To use not line-break at all,
specify the empty array (i.e. new byte[0]) as line-break
parameter.
Base64InputStream| Constructor and Description |
|---|
Base64OutputStream(java.io.OutputStream out)
Creates a new Base64OutputStream to write Base64 encoded data to the
specified underlying output stream.
|
Base64OutputStream(java.io.OutputStream out,
byte[] lineBreakChars)
Creates a new Base64OutputStream to write Base64 encoded data to the
specified underlying output stream and specifies the line break delimiter.
|
Base64OutputStream(java.io.OutputStream out,
byte[] lineBreakChars,
boolean urlEncoding,
boolean usePadding)
Creates a new Base64OutputStream to write Base64 encoded data to the
specified underlying output stream, specifies the line break delimiter,
and specifies whether to use Base64UrlEncoding and the usage of trailing
padding "=" bytes.
|
| Modifier and Type | Method and Description |
|---|---|
void |
flush()
Performs final processing and output to the output stream.
|
byte[] |
getInstanceLineBreak()
Gets the line-break delimiter used by this Base64OutputStream instance.
|
static byte[] |
getLineBreak()
Gets the default line-break delimiter.
|
static void |
setLineBreak(byte[] lineBreakChars)
Sets the line-break delimiter to be used throughout the application;
default is CR + LF (0x0D, 0x0A).
|
void |
write(byte[] in,
int inOff,
int inLen)
Base64 encodes 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)
out - - the underlying output stream.public Base64OutputStream(java.io.OutputStream out,
byte[] lineBreakChars)
out - - the underlying output stream.lineBreakChars - - the lineBreak the line-break delimiter to be used; if
null, the currently static set line-break delimiter
CRLF (0x0D, 0x0A) will be used. Provide an empty array to disable
line breaks.setLineBreak(byte[]),
getLineBreak(),
getInstanceLineBreak()public Base64OutputStream(java.io.OutputStream out,
byte[] lineBreakChars,
boolean urlEncoding,
boolean usePadding)
out - - the underlying output stream.lineBreakChars - - the lineBreak the line-break delimiter to be used; if
null, the currently static set line-break delimiter
CRLF (0x0D, 0x0A) will be used. Provide an empty array to disable
line breaks.urlEncoding - - iff true, the stream writes Base64UrlEncoding. Standard Base64 otherwise.usePadding - - iff true, the stream appends trailing "=" if necessary. Iff false, the
implementation does not append padding bytessetLineBreak(byte[]),
getLineBreak(),
getInstanceLineBreak()public static void setLineBreak(byte[] lineBreakChars)
lineBreakChars - The line-break to be used. Specify the empty array to use no
line-break.java.lang.IllegalArgumentException - If lineBreakChars is null.public static byte[] getLineBreak()
public byte[] getInstanceLineBreak()
public 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.