|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.util.Base64Decoder
public class Base64Decoder
Base-64 decoding 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 radix-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 radix-64 encoded data (as a sequence of 8-bit characters) back into straight binary data is the reverse operation, substituting each radix-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 radix-64 encoded data.
This class can be used as a simple replacement for the
sun.misc.BASE64Decoder
class.
Base64Encoder
,
sun.misc.BASE64Decoder
Field Summary | |
---|---|
static int |
SERIES
Class revision number. |
Constructor Summary | |
---|---|
Base64Decoder()
Default constructor. |
Method Summary | |
---|---|
byte[] |
decodeBuffer(java.lang.String chars)
Decode base-64 characters into binary data. |
static byte[] |
decodeBytes(byte[] chars)
Decode base-64 character bytes into binary data. |
static byte[] |
decodeBytes(byte[] chars,
int off,
int len)
Decode base-64 character bytes into binary data. |
static int |
decodeBytes(byte[] chars,
int off,
int len,
byte[] dec,
int decOff)
Decode base-64 character bytes into binary data. |
static byte[] |
decodeString(java.lang.String chars)
Decode base-64 characters into binary data. |
static int |
decodeString(java.lang.String chars,
byte[] dec,
int off)
Decode base-64 characters into binary data. |
static int |
fromBase64(int ch)
Convert a radix-64 printable ASCII character code into its corresponding 6-bit binary value. |
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 Base64Decoder()
This constructor is provided for compatibility with the
sun.misc.BASE64Decoder
class, which allows this class to be used
as a simple replacement for it.
Method Detail |
---|
public static byte[] decodeString(java.lang.String chars) throws java.text.ParseException
chars
- (const)
Printable ASCII string containing binary data encoded as radix-64
characters.
java.text.ParseException
- Thrown if chars is malformed or contains an invalid character
code.decodeString()
,
Base64Encoder.encodeAsString()
public static int decodeString(java.lang.String chars, byte[] dec, int off) throws java.text.ParseException
See decodeBytes()
for more details.
chars
- (const)
Printable ASCII string containing binary data encoded as radix-64
characters.
dec
- Decoded byte (8-bit octet) array, which is filled with the decoded data.off
- Index of the first byte (8-bit octet) within dec to write to.
java.text.ParseException
- Thrown if chars is malformed or contains an invalid character
code.decodeString()
,
Base64Encoder.encodeAsString()
public static byte[] decodeBytes(byte[] chars) throws java.text.ParseException
See decodeBytes()
for more details.
chars
- (const)
An array of bytes containing printable ASCII characters, representating
binary data encoded as radix-64 characters.
java.text.ParseException
- Thrown if chars is malformed or contains an invalid character
code.decodeBytes()
,
Base64Encoder.encodeAsBytes()
public static byte[] decodeBytes(byte[] chars, int off, int len) throws java.text.ParseException
See decodeBytes()
for more details.
chars
- (const)
An array of bytes containing printable ASCII characters, representating
binary data encoded as radix-64 characters.
off
- Index of the first byte (8-bit octet) within chars to decode.len
- Number of bytes (8-bit octets) to decode from chars.
java.text.ParseException
- Thrown if chars is malformed or contains an invalid character
code.decodeBytes()
,
Base64Encoder.encodeAsBytes()
public static int decodeBytes(byte[] chars, int off, int len, byte[] dec, int decOff) throws java.text.ParseException
+-----------+-----------+-----------+-----------+ | sextet | sextet | sextet | sextet | |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| input sextets :- - - - - -:- -:- - - -:- - - -:- -:- - - - - -: |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| output octets | octet | octet | octet | +---------------+---------------+---------------+ +-----------+-----------+-----------+-----------+ | sextet | sextet | sextet | padding | |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| '=' | input sextets :- - - - - -:- -:- - - -:- - - -:- -:- - - - - -: |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|x x : output octets | octet | octet | discarded : +---------------+---------------+ - - - - - - - + +-----------+-----------+-----------+-----------+ | sextet | sextet | padding | padding | |5 4 3 2 1 0|5 4 3 2 1 0| '=' | '=' | input sextets :- - - - - -:- -:- - - -:- - - -:- -:- - - - - -: |7 6 5 4 3 2 1 0|x x x x : : output octets | octet | discarded : discarded : +---------------+ - - - - - - - + - - - - - - - +
For example, the following table list some sextet sequences and their resulting octet decodings:
04,11,04,11 => 11,11,11 04,12,08,33 => 11,22,33 3F,3F,3F,3F => FF,FF,FF 04,11,04, = => 11,11 04,11,07, = => 11,11 3F,3F,3C, = => FF,FF 04,10, =, = => 11 04,1F, =, = => 11 3F,30, =, = => FF 3F,30,03,3F,00,0F,3C,00 => FF,00,FF,00,FF,00
chars
- (const)
An array of bytes containing printable ASCII characters, representating
binary data encoded as radix-64 characters.
off
- Index of the first byte (8-bit octet) within chars to decode.len
- Number of bytes (8-bit octets) to decode from chars.dec
- Decoded byte (8-bit octet) array, which is filled with the decoded data.decOff
- Index of the first byte (8-bit octet) within dec to write to.
java.text.ParseException
- Thrown if chars is malformed or contains an invalid character
code.Base64Encoder.encodeAsBytes()
public static int fromBase64(int ch)
ch
- A printable radix-64 ASCII character code.
Base64Encoder.toBase64()
public byte[] decodeBuffer(java.lang.String chars)
This method is provided for compatibility, producing the same result as
the decodeBuffer() method of the sun.misc.BASE64Decoder
class.
chars
- (const)
Printable ASCII string containing binary data encoded as radix-64
characters.
java.lang.IllegalArgumentException
- (unchecked)
Thrown if chars is malformed or contains an invalid character
code.decodeString()
,
Base64Encoder.encode()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |