public class Base64InputStream
extends java.io.FilterInputStream
read
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 decoding Base64 encoding data read in from some file, e.g.:
FileInputStream fis = new FileInputStream("test/base64.enc");
Base64InputStream base64is = new Base64InputStream(fis);
byte[] data = new byte[1000];
int r;
while ((r = base64is.read(data)) != -1) {
System.out.print(new String(data));
}
Base64OutputStream| Modifier and Type | Field and Description |
|---|---|
protected int[] |
decoding |
protected static int |
ERROR |
protected static int |
IGNORE |
protected static int |
NOTIFY |
protected static int |
TERMINATE |
| Constructor and Description |
|---|
Base64InputStream(java.io.InputStream in)
Creates a new Base64InputStream to read data from the specified input stream.
|
Base64InputStream(java.io.InputStream in,
boolean ignoreInvalidCharacters)
Creates a new Base64InputStream to read data from the specified input stream
and specifies whether or not to ignore invalid BASE-64 characters.
|
Base64InputStream(java.io.InputStream in,
boolean ignoreInvalidCharacters,
int[][] overrideDecodingTable)
Creates a new Base64InputStream to read data from the specified input
stream along with allowing you to specify whether or not to ignore
invalid BASE-64 characters and allowing you to override the default
decoding table
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
notify(byte[] buffer)
This method is called if a character specified with
NOTIFY is encountered. |
int |
read()
Returns the next BASE64 decoded byte, read from the underlying input stream.
|
int |
read(byte[] b,
int off,
int len)
Reads and decodes the specified number of data bytes from the underlying input
stream into a byte array until bytes are available.
|
void |
setIgnoreInvalidCharacters(boolean ignoreInvalidCharacters)
Sets whether or not to ignore invalid BASE-64 characters in the input.
|
protected int[] decoding
protected static final int ERROR
protected static final int IGNORE
protected static final int NOTIFY
protected static final int TERMINATE
public Base64InputStream(java.io.InputStream in)
in - the underlying input stream.public Base64InputStream(java.io.InputStream in,
boolean ignoreInvalidCharacters)
in - the underlying input stream.public Base64InputStream(java.io.InputStream in,
boolean ignoreInvalidCharacters,
int[][] overrideDecodingTable)
in - the underlying input stream.ignoreInvalidCharacters - flag to ignore invalid charsoverrideDecodingTable - to override the default decoding tablepublic void setIgnoreInvalidCharacters(boolean ignoreInvalidCharacters)
public int read(byte[] b,
int off,
int len)
throws java.io.IOException,
Base64Exception
The bytes are decoded and read to the given byte array, beginning at position
off. The number of bytes read to the array are returned.
read in class java.io.FilterInputStreamb - the byte array into which the decoded bytes are readoff - the offset indicating the position in b to which the
first decoded byte shall be readlen - the maximum number of bytes to be readjava.io.IOException - if an I/O error occurs.Base64Exception - if there is an Base64 format errorprotected void notify(byte[] buffer)
throws java.io.IOException
NOTIFY is encountered.
This method does nothing and shall be overwritten by a sub-class.buffer - the characters already read from the input stream; and the
first one was marked with NOTIFYjava.io.IOException - allows the subclass to throw an Exception if an error occurspublic int read()
throws java.io.IOException,
Base64Exception
read in class java.io.FilterInputStreamjava.io.IOException - if an I/O error occursBase64Exception - if there is a Base64 format error