Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.
Uses the "URL and Filename safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.
Uses "The Base64 Alphabet" as specified in Table 1 of
RFC 2045 for encoding and decoding operation. The encoded output
must be represented in lines of no more than 76 characters each
and uses a carriage return '\r' followed immediately by
a linefeed '\n' as the line separator. No line separator
is added to the end of the encoded output. All line separators
or other characters not found in the base64 alphabet table are
ignored in decoding operation.
Unless otherwise noted, passing a null argument to a
method of this class will cause a NullPointerException to be thrown.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static class | Base64.
This class implements a decoder for decoding byte data using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. |
| public static class | Base64.
This class implements an encoder for encoding byte data using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. |
| private static class |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Base64. | Returns: A Base64 decoder.Returns a |
| public static Base64. | Returns: A Base64 encoder.Returns a |
| public static Base64. | Returns: A Base64 decoder.Returns a |
| public static Base64. | Returns: A Base64 encoder.Returns a |
| public static Base64. | Returns: A Base64 encoder.the length of each output line (rounded down to nearest multiple
of 4). If the rounded down line length is not a positive value,
the output will not be separated in lines lineLength, byte[] the line separator for each output line lineSeparator)Returns a |
| public static Base64. | Returns: A Base64 decoder.Returns a |
| public static Base64. | Returns: A Base64 encoder.Returns a |
| Base64 | back to summary |
|---|---|
| private Base64() | |
| getDecoder | back to summary |
|---|---|
| public static Base64. Returns a | |
| getEncoder | back to summary |
|---|---|
| public static Base64. Returns a | |
| getMimeDecoder | back to summary |
|---|---|
| public static Base64. Returns a | |
| getMimeEncoder | back to summary |
|---|---|
| public static Base64. Returns a | |
| getMimeEncoder | back to summary |
|---|---|
| public static Base64. Returns a
| |
| getUrlDecoder | back to summary |
|---|---|
| public static Base64. Returns a | |
| getUrlEncoder | back to summary |
|---|---|
| public static Base64. Returns a | |
| Modifier and Type | Field and Description |
|---|---|
| private final int[] | |
| private int | |
| private boolean | |
| private boolean | |
| private final InputStream | |
| private final boolean | |
| private int | |
| private byte[] | |
| private int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. |
| public void | close()
Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream. |
| private int | |
| private int | |
| private int | |
| public int | read()
Implements abstract java. Reads the next byte of data from the input stream. |
| public int | read(byte[] b, int off, int len)
Overrides java. Reads up to |
| base64 | back to summary |
|---|---|
| private final int[] base64 | |
| bits | back to summary |
|---|---|
| private int bits | |
| closed | back to summary |
|---|---|
| private boolean closed | |
| eof | back to summary |
|---|---|
| private boolean eof | |
| is | back to summary |
|---|---|
| private final InputStream is | |
| isMIME | back to summary |
|---|---|
| private final boolean isMIME | |
| rpos | back to summary |
|---|---|
| private int rpos | |
| sbBuf | back to summary |
|---|---|
| private byte[] sbBuf | |
| wpos | back to summary |
|---|---|
| private int wpos | |
| DecInputStream | back to summary |
|---|---|
| pack-priv DecInputStream(InputStream is, int[] base64, boolean isMIME) | |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. Doc from java. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of A subclass's implementation of this method may choose to throw an
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this input stream and releases any system resources associated with the stream.
| |
| eof | back to summary |
|---|---|
| private int eof(byte[] b, int off, int pos, int limit) throws IOException | |
| leftovers | back to summary |
|---|---|
| private int leftovers(byte[] b, int off, int pos, int limit) | |
| padding | back to summary |
|---|---|
| private int padding(byte[] b, int off, int pos, int limit) throws IOException | |
| read | back to summary |
|---|---|
| public int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
The Base64 padding character '=' is accepted and
interpreted as the end of the encoded byte data, but is not
required. So if the final unit of the encoded byte data only has
two or three Base64 characters (without the corresponding padding
character(s) padded), they are decoded as if followed by padding
character(s). If there is a padding character present in the
final unit, the correct number of padding character(s) must be
present, otherwise IllegalArgumentException (
IOException when reading from a Base64 stream) is thrown
during decoding.
Instances of Decoder class are safe for use by
multiple concurrent threads.
Unless otherwise noted, passing a null argument to
a method of this class will cause a
NullPointerException to
be thrown.
If the decoded byte output of the needed size can not
be allocated, the decode methods of this class will
cause an OutOfMemoryError
to be thrown.
Encoder
| Modifier and Type | Field and Description |
|---|---|
| private static final int[] | fromBase64
Lookup table for decoding unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. |
| private static final int[] | fromBase64URL
Lookup table for decoding "URL and Filename safe Base64 Alphabet" as specified in Table2 of the RFC 4648. |
| private final boolean | |
| private final boolean | |
| pack-priv static final Base64. | |
| pack-priv static final Base64. | |
| pack-priv static final Base64. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public byte[] | |
| public byte[] | |
| public int | |
| public ByteBuffer | Returns: A newly-allocated byte buffer containing the decoded bytesthe ByteBuffer to decode buffer)Decodes all bytes from the input byte buffer using the |
| private int | |
| private int | Returns: the number of destination data bytes producedthe source byte array of Base64 encoded bytes src, int the offset into src array to begin reading sp, int the offset (exclusive) past the last byte to be converted. sl, byte[] the destination byte array of decoded data bytes dst, int the offset into dst array to begin writing dp, boolean boolean, when true decode RFC4648 URL-safe base64 characters isURL, boolean boolean, when true decode according to RFC2045 (ignore illegal chars) isMIME)Decodes base64 characters, and returns the number of data bytes written into the destination array. |
| private int | Returns: length of the decoded bytesthe byte array to decode src, int the source position sp, int the source limit sl)Calculates the length of the decoded output bytes. |
| public InputStream | Returns: the input stream for decoding the specified Base64 encoded byte streamthe input stream is)Returns an input stream for decoding |
| fromBase64 | back to summary |
|---|---|
| private static final int[] fromBase64 Lookup table for decoding unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the array are encoded to -1. | |
| fromBase64URL | back to summary |
|---|---|
| private static final int[] fromBase64URL Lookup table for decoding "URL and Filename safe Base64 Alphabet" as specified in Table2 of the RFC 4648. | |
| isMIME | back to summary |
|---|---|
| private final boolean isMIME | |
| isURL | back to summary |
|---|---|
| private final boolean isURL | |
| RFC2045 | back to summary |
|---|---|
| pack-priv static final Base64. | |
| RFC4648 | back to summary |
|---|---|
| pack-priv static final Base64. | |
| RFC4648_URLSAFE | back to summary |
|---|---|
| pack-priv static final Base64. | |
| Decoder | back to summary |
|---|---|
| private Decoder(boolean isURL, boolean isMIME) | |
| decode | back to summary |
|---|---|
| public byte[] decode(byte[] src) Decodes all bytes from the input byte array using the
| |
| decode | back to summary |
|---|---|
| public byte[] decode(String src) Decodes a Base64 encoded String into a newly-allocated byte array
using the An invocation of this method has exactly the same effect as invoking
| |
| decode | back to summary |
|---|---|
| public int decode(byte[] src, byte[] dst) Decodes all bytes from the input byte array using the It is the responsibility of the invoker of this method to make
sure the output byte array If the input byte array is not in valid Base64 encoding scheme then some bytes may have been written to the output byte array before IllegalargumentException is thrown.
| |
| decode | back to summary |
|---|---|
| public ByteBuffer decode(ByteBuffer buffer) Decodes all bytes from the input byte buffer using the Upon return, the source buffer's position will be updated to its limit; its limit will not have been changed. The returned output buffer's position will be zero and its limit will be the number of resulting decoded bytes
| |
| decode0 | back to summary |
|---|---|
| private int decode0(byte[] src, int sp, int sl, byte[] dst) | |
| decodeBlock | back to summary |
|---|---|
| private int decodeBlock(byte[] src, int sp, int sl, byte[] dst, int dp, boolean isURL, boolean isMIME) Decodes base64 characters, and returns the number of data bytes written into the destination array. It is the fast path for full 4-byte to 3-byte decoding w/o errors. decodeBlock() can be overridden by an arch-specific intrinsic. decodeBlock can choose to decode all, none, or a variable-sized prefix of the src bytes. This allows the intrinsic to decode in chunks of the src that are of a favorable size for the specific processor it's running on. If any illegal base64 bytes are encountered in src by the intrinsic, the intrinsic must return the actual number of valid data bytes already written to dst. Note that the '=' pad character is treated as an illegal Base64 character by decodeBlock, so it will not process a block of 4 bytes containing pad characters. However, MIME decoding ignores illegal characters, so any intrinsic overriding decodeBlock can choose how to handle illegal characters based on the isMIME parameter. Given the parameters, no length check is possible on dst, so dst is assumed to be large enough to store the decoded bytes.
| |
| decodedOutLength | back to summary |
|---|---|
| private int decodedOutLength(byte[] src, int sp, int sl) Calculates the length of the decoded output bytes.
| |
| wrap | back to summary |
|---|---|
| public InputStream wrap(InputStream is) Returns an input stream for decoding The Closing the returned input stream will close the underlying input stream.
| |
Instances of Encoder class are safe for use by
multiple concurrent threads.
Unless otherwise noted, passing a null argument to
a method of this class will cause a
NullPointerException to
be thrown.
If the encoded byte output of the needed size can not
be allocated, the encode methods of this class will
cause an OutOfMemoryError
to be thrown.
Decoder
| Modifier and Type | Field and Description |
|---|---|
| private static final byte[] | |
| private final boolean | |
| private final boolean | |
| private static final JavaLangAccess | |
| private final int | |
| private static final int | |
| private final byte[] | |
| pack-priv static final Base64. | |
| pack-priv static final Base64. | |
| pack-priv static final Base64. | |
| private static final char[] | toBase64
This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). |
| private static final char[] | toBase64URL
It's the lookup table for "URL and Filename safe Base64" as specified in Table 2 of the RFC 4648, with the '+' and '/' changed to '-' and '_'. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public byte[] | |
| public int | |
| public ByteBuffer | Returns: A newly-allocated byte buffer containing the encoded bytes.the source ByteBuffer to encode buffer)Encodes all remaining bytes from the specified byte buffer into
a newly-allocated ByteBuffer using the |
| private int | |
| private void | |
| private final int | Returns: length of the encoded bytes, or -1 if the length overflowslength of the bytes to encode srclen, boolean if true, throws OutOfMemoryError if the length of
the encoded bytes overflows; else returns the
length throwOOME)Calculates the length of the encoded output bytes. |
| public String | Returns: A String containing the resulting Base64 encoded charactersthe byte array to encode src)Encodes the specified byte array into a String using the |
| public Base64. | Returns: an equivalent encoder that encodes without adding any padding character at the endReturns an encoder instance that encodes equivalently to this one, but without adding any padding character at the end of the encoded byte data. |
| public OutputStream | Returns: the output stream for encoding the byte data into the specified Base64 encoded formatthe output stream. os)Wraps an output stream for encoding byte data using the |
| CRLF | back to summary |
|---|---|
| private static final byte[] CRLF | |
| doPadding | back to summary |
|---|---|
| private final boolean doPadding | |
| isURL | back to summary |
|---|---|
| private final boolean isURL | |
| JLA | back to summary |
|---|---|
| private static final JavaLangAccess JLA | |
| linemax | back to summary |
|---|---|
| private final int linemax | |
| MIMELINEMAX | back to summary |
|---|---|
| private static final int MIMELINEMAX | |
| newline | back to summary |
|---|---|
| private final byte[] newline | |
| RFC2045 | back to summary |
|---|---|
| pack-priv static final Base64. | |
| RFC4648 | back to summary |
|---|---|
| pack-priv static final Base64. | |
| RFC4648_URLSAFE | back to summary |
|---|---|
| pack-priv static final Base64. | |
| toBase64 | back to summary |
|---|---|
| private static final char[] toBase64 This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). | |
| toBase64URL | back to summary |
|---|---|
| private static final char[] toBase64URL It's the lookup table for "URL and Filename safe Base64" as specified in Table 2 of the RFC 4648, with the '+' and '/' changed to '-' and '_'. This table is used when BASE64_URL is specified. | |
| Encoder | back to summary |
|---|---|
| private Encoder(boolean isURL, byte[] newline, int linemax, boolean doPadding) | |
| encode | back to summary |
|---|---|
| public byte[] encode(byte[] src) Encodes all bytes from the specified byte array into a newly-allocated
byte array using the
| |
| encode | back to summary |
|---|---|
| public int encode(byte[] src, byte[] dst) Encodes all bytes from the specified byte array using the
It is the responsibility of the invoker of this method to make
sure the output byte array
| |
| encode | back to summary |
|---|---|
| public ByteBuffer encode(ByteBuffer buffer) Encodes all remaining bytes from the specified byte buffer into
a newly-allocated ByteBuffer using the
| |
| encode0 | back to summary |
|---|---|
| private int encode0(byte[] src, int off, int end, byte[] dst) | |
| encodeBlock | back to summary |
|---|---|
private void encodeBlock(byte[] src, int sp, int sl, byte[] dst, int dp, boolean isURL)
| |
| encodedOutLength | back to summary |
|---|---|
| private final int encodedOutLength(int srclen, boolean throwOOME) Calculates the length of the encoded output bytes.
| |
| encodeToString | back to summary |
|---|---|
| public String encodeToString(byte[] src) Encodes the specified byte array into a String using the This method first encodes all input bytes into a base64 encoded
byte array and then constructs a new String by using the encoded byte
array and the In other words, an invocation of this method has exactly the same
effect as invoking
| |
| withoutPadding | back to summary |
|---|---|
| public Base64. Returns an encoder instance that encodes equivalently to this one, but without adding any padding character at the end of the encoded byte data. The encoding scheme of this encoder instance is unaffected by this invocation. The returned encoder instance should be used for non-padding encoding operation. | |
| wrap | back to summary |
|---|---|
| public OutputStream wrap(OutputStream os) Wraps an output stream for encoding byte data using the It is recommended to promptly close the returned output stream after use, during which it will flush all possible leftover bytes to the underlying output stream. Closing the returned output stream will close the underlying output stream.
| |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int | |
| private int | |
| private final char[] | |
| private byte[] | |
| private boolean | |
| private final boolean | |
| private int | |
| private final int | |
| private int | |
| private final byte[] |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | close()
Overrides java. Implements java. Closes this output stream and releases any system resources associated with the stream. |
| public void | write(int b)
Overrides java. Writes the specified |
| public void | write(byte[] b, int off, int len)
Overrides java. Writes |
| private void |
| b0 | back to summary |
|---|---|
| private int b0 | |
| b1 | back to summary |
|---|---|
| private int b1 | |
| b2 | back to summary |
|---|---|
| private int b2 | |
| base64 | back to summary |
|---|---|
| private final char[] base64 | |
| buf | back to summary |
|---|---|
| private byte[] buf | |
| closed | back to summary |
|---|---|
| private boolean closed | |
| doPadding | back to summary |
|---|---|
| private final boolean doPadding | |
| leftover | back to summary |
|---|---|
| private int leftover | |
| linemax | back to summary |
|---|---|
| private final int linemax | |
| linepos | back to summary |
|---|---|
| private int linepos | |
| newline | back to summary |
|---|---|
| private final byte[] newline | |
| EncOutputStream | back to summary |
|---|---|
| pack-priv EncOutputStream(OutputStream os, char[] base64, byte[] newline, int linemax, boolean doPadding) | |
| checkNewline | back to summary |
|---|---|
| private void checkNewline() throws IOException | |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this output stream and releases any system resources associated with the stream.
| |
| write | back to summary |
|---|---|
| public void write(int b) throws IOException Overrides java. Doc from java. Writes the specified
The
Implements the abstract
| |
| write | back to summary |
|---|---|
| public void write(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Writes
| |
| writeb4 | back to summary |
|---|---|
| private void writeb4(char b1, char b2, char b3, char b4) throws IOException | |