|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.yosokumo.core.Base64
class Base64
Provides methods for converting byte sequences to Base64 character strings and vice versa.
public static String encodeBytes(byte[] source)
public static byte[] decodeString(String source)
encodeBytes
, the call decodeString(C)
will
return the original byte sequence. However, there exist character
sequences which are never produced by encodeBytes
, and, hence,
applying decodeString
to such character sequences produces byte
sequences from which the original character sequences cannot be recovered.
For example, decodeString
converts both AA== and AB== to the single
byte 0, and encodeBytes
converts the single byte 0 to AA==. There
does not exist a sequence of bytes which will cause encodeBytes
to
return AB==.
Field Summary | |
---|---|
private static char[] |
encode64
Base64 character set: A-Z, a-z, 0-9, +, /. |
Constructor Summary | |
---|---|
Base64()
|
Method Summary | |
---|---|
(package private) static byte |
decode64(char c)
Convert a 6-bit Base64 character to an 8-bit byte. |
static byte[] |
decodeString(java.lang.String source)
Convert a Base64 string to a sequence of bytes. |
static java.lang.String |
encodeBytes(byte[] source)
Convert a sequence of bytes to a Base64 string. |
private static void |
map3to4(byte A,
byte B,
byte C,
java.lang.StringBuilder abcd)
Convert a sequence of three bytes to a sequence of four characters. |
private static void |
map4to3(char a,
char b,
char c,
char d,
byte[] ABC,
int j,
int n)
Convert a sequence of four characters to a sequence of three bytes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final char[] encode64
Constructor Detail |
---|
Base64()
Method Detail |
---|
private static void map3to4(byte A, byte B, byte C, java.lang.StringBuilder abcd)
765432 10 7654 3210 76 543210 +---------+---------+---------+ |AAAAAA AA|BBBB BBBB|CC CCCCCC| +------+-------+-------+------+ |aaaaaa|bb bbbb|cccc cc|dddddd| +------+-------+-------+------+ 543210 54 3210 5432 10 543210
A
- the first byte.B
- the second byte.C
- the third byte.abcd
- the resulting four characters are appended to abcd.public static java.lang.String encodeBytes(byte[] source)
source
- is a sequence of zero or more 8-bit bytes.
static byte decode64(char c)
c
- a 6-bit Base64 character.
java.lang.IllegalArgumentException
- if the input character is not a
Base64 character.private static void map4to3(char a, char b, char c, char d, byte[] ABC, int j, int n)
a
- the first character.b
- the second character.c
- the third character.d
- the fourth character.ABC
- the resulting three bytes are stored here.j
- an index to the first byte in ABC to change.n
- 1, 2, or 3, indicating how many bytes to store in ABC.
java.lang.IllegalArgumentException
- if any input character is not a
Base64 character.public static byte[] decodeString(java.lang.String source)
source
- a string of zero or more 6-bit Base64 characters.
java.lang.IllegalArgumentException
- if the length of the input string is
not a multiple of four.
java.lang.IllegalArgumentException
- if the input string contains a
character which is not a Base64 character.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |