public class Base64
extends java.lang.Object
I am placing this code in the Public Domain. Do with it as you will. This software comes with no guarantees or warranties but with plenty of well-wishing instead! Please visit http://iharder.net/base64 periodically to check for updates or to contribute improvements.
Modifier and Type | Field and Description |
---|---|
private static byte[] |
DEC
Translates a Base64 value to either its 6-bit reconstruction value or a
negative number indicating some other meaning.
|
private static byte[] |
ENC
The 64 valid Base64 values.
|
private static byte |
EQUALS_SIGN
The equals sign (=) as a byte.
|
private static byte |
EQUALS_SIGN_DEC
Indicates equals sign in encoding.
|
private static byte |
INVALID_DEC
Indicates an invalid byte during decoding.
|
private static byte |
WHITE_SPACE_DEC
Indicates white space in encoding.
|
Modifier | Constructor and Description |
---|---|
private |
Base64()
Defeats instantiation.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
decode(byte[] source,
int off,
int len)
Low-level decoding ASCII characters from a byte array.
|
static byte[] |
decode(java.lang.String s)
Decodes data from Base64 notation.
|
private static int |
decode4to3(byte[] source,
int srcOffset,
byte[] destination,
int destOffset)
Decodes four bytes from array source and writes the resulting
bytes (up to three of them) to destination.
|
private static void |
encode3to4(byte[] source,
int srcOffset,
int numSigBytes,
byte[] destination,
int destOffset)
Encodes up to three bytes of the array source and writes the
resulting four Base64 bytes to destination.
|
static java.lang.String |
encodeBytes(byte[] source)
Encodes a byte array into Base64 notation.
|
static java.lang.String |
encodeBytes(byte[] source,
int off,
int len)
Encodes a byte array into Base64 notation.
|
private static final byte EQUALS_SIGN
private static final byte EQUALS_SIGN_DEC
private static final byte WHITE_SPACE_DEC
private static final byte INVALID_DEC
private static final byte[] ENC
private static final byte[] DEC
private static void encode3to4(byte[] source, int srcOffset, int numSigBytes, byte[] destination, int destOffset)
source
- the array to convertsrcOffset
- the index where conversion beginsnumSigBytes
- the number of significant bytes in your arraydestination
- the array to hold the conversiondestOffset
- the index where output will be putpublic static java.lang.String encodeBytes(byte[] source)
source
- The data to convertpublic static java.lang.String encodeBytes(byte[] source, int off, int len)
source
- The data to convertoff
- Offset in array where conversion should beginlen
- Length of data to convertprivate static int decode4to3(byte[] source, int srcOffset, byte[] destination, int destOffset)
source
- the array to convertsrcOffset
- the index where conversion beginsdestination
- the array to hold the conversiondestOffset
- the index where output will be putpublic static byte[] decode(byte[] source, int off, int len)
source
- The Base64 encoded dataoff
- The offset of where to begin decodinglen
- The length of characters to decodejava.lang.IllegalArgumentException
- the input is not a valid Base64 sequence.public static byte[] decode(java.lang.String s)
s
- the string to decode