|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecttribble.util.Base64Encoder
public class Base64Encoder
Base-64 encoding methods.
Base-64 encoding (a.k.a. radix-64 encoding) is a form of encoding binary data in 6-bit units. (6 bits provides 64 distinct binary values, hence the moniker base-64 or radix-64.) Groups of three 8-bit octets (bytes), totalling 24 bits, can be converted into four 6-bit units. Each 6-bit unit can in turn be represented by one of 64 unique printable ASCII (8-bit) characters.
Converting straight binary data (as a sequence of 8-bit octets) into a base-64 representation is thus simply the the process of packing groups of three 8-bit octets into four 6-bit units, and then substituting each 6-bit unit with its corresponding ASCII character code.
Converting base-64 encoded data (as a sequence of 8-bit characters) back into straight binary data is the reverse operation, substituting each base-64 ASCII character code with its corresponding 6-bit unit, then unpacking groups of four 6-bit units into three 8-bit octets.
A 65th special ASCII character is used to indicate trailing padding in base-64 encoded data.
This class can be used as a simple replacement for the
sun.misc.BASE64Encoder class.
Base64Decoder,
sun.misc.BASE64Encoder| Field Summary | |
|---|---|
static int |
SERIES
Class revision number. |
| Constructor Summary | |
|---|---|
Base64Encoder()
Default constructor. |
|
| Method Summary | |
|---|---|
java.lang.String |
encode(byte[] data)
Encode binary data as base-64 characters. |
static byte[] |
encodeAsBytes(byte[] data)
Encode binary data as base-64 character octets. |
static byte[] |
encodeAsBytes(byte[] data,
int off,
int len)
Encode binary data as base-64 characters. |
static int |
encodeAsBytes(byte[] data,
int off,
int len,
byte[] enc,
int encOff)
Encode binary data as base-64 characters. |
static java.lang.String |
encodeAsString(byte[] data)
Encode binary data as base-64 characters. |
static java.lang.String |
encodeAsString(byte[] data,
int off,
int len)
Encode binary data as base-64 characters. |
static byte |
toBase64(int bits)
Convert a 6-bit binary value into its corresponding base-64 printable ASCII character code. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int SERIES
| Constructor Detail |
|---|
public Base64Encoder()
This constructor is provided for compatibility with the
sun.misc.BASE64Encoder class, which allows this class to be used
as a simple replacement for it.
| Method Detail |
|---|
public static java.lang.String encodeAsString(byte[] data)
data - (const)
Binary data, as an array of bytes (8-bit octets).
encodeAsString(),
Base64Decoder.decodeString()
public static java.lang.String encodeAsString(byte[] data,
int off,
int len)
data - (const)
Binary data, as an array of bytes (8-bit octets).off - Index of the first byte (octet) within data to encode.len - Number of bytes (octets) within data to encode.
encodeAsBytes(),
Base64Decoder.decodeString()public static byte[] encodeAsBytes(byte[] data)
data - (const)
Binary data, as an array of bytes (8-bit octets).
encodeAsBytes(),
Base64Decoder.decodeBytes()
public static byte[] encodeAsBytes(byte[] data,
int off,
int len)
data - (const)
Binary data, as an array of bytes (8-bit octets).off - Index of the first byte (octet) within data to encode.len - Number of bytes (octets) within data to encode.
encodeAsBytes(),
Base64Decoder.decodeBytes()
public static int encodeAsBytes(byte[] data,
int off,
int len,
byte[] enc,
int encOff)
Base-64 (a.k.a. radix-64) encoding converts 8-bit bytes (octets) into characters by encoding 6 bits of data (sextets) in each output character; thus 3 8-bit input bytes can be converted into 4 6-bit output characters (for a total of 24 data bits). Any input bytes left over (two or less) are converted and padded.
+---------------+---------------+---------------+
| octet | octet | octet |
|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| input octets
:- - - - - -:- -:- - - -:- - - -:- -:- - - - - -:
|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| output sextets
| sextet | sextet | sextet | sextet |
+-----------+-----------+-----------+-----------+
+---------------+---------------+ - - - - - - - +
| octet | octet | no data :
|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| : input octets
:- - - - - -:- -:- - - -:- - - -:- -:- - - - - -:
|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 z z| '=' | output sextets
| sextet | sextet | sextet | padding |
+-----------+-----------+-----------+-----------+
+---------------+ - - - - - - - + - - - - - - - +
| octet | no data : no data :
|7 6 5 4 3 2 1 0| : : input octets
:- - - - - -:- -:- - - -:- - - -:- -:- - - - - -:
|5 4 3 2 1 0|5 4 z z z z| '=' | '=' | output sextets
| sextet | sextet | padding | padding |
+-----------+-----------+-----------+-----------+
For example, the following table list some octet sequences and their resulting sextet encodings:
11,11,11 => 04,11,04,11
11,22,33 => 04,12,08,33
FF,FF,FF => 3F,3F,3F,3F
11,11 => 04,11,04, =
FF,FF => 3F,3F,3C, =
11 => 04,10, =, =
FF => 3F,30, =, =
FF,00,FF,00,FF,00 => 3F,30,03,3F,00,0F,3C,00
data - (const)
Binary data, as an array of bytes (8-bit octets).off - Index of the first byte (octet) within data to encode.len - Number of bytes (octets) within data to encode.enc - An array of bytes into which will be written printable ASCII characters
representating the contents of data encoded as base-64
characters.encOff - Index of the first byte (octet) within enc to write to.
encodeAsBytes(),
Base64Decoder.decodeBytes()public static byte toBase64(int bits)
bits - A 6-bit binary value in the range [0,63]; or the value 64, indicating the
special trailing padding character code; or the character '?',
indicating an invalid 6-bit code.
Base64Decoder.fromBase64()public java.lang.String encode(byte[] data)
This method produces the same result as the encode() method
of the sun.misc.BASE64Encoder class.
data - (const)
Binary data, as an array of bytes (8-bit octets).
encodeAsString(),
Base64Decoder.decodeString()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||