com.ls.util.bytes
Class Base64
java.lang.Object
|
+--com.ls.util.bytes.Base64
- public class Base64
- extends Object
Encode arbitrary binary into printable ASCII using BASE64 encoding.
Base64 is a way of encoding 8-bit characters using only ASCII printable
characters sometimes called UUENCODE.
The specification is described in RFC 2045. Base64 is a scheme where
3 bytes are concatenated, then split to form 4 groups of 6-bits each; and
each 6-bits gets translated to an encoded printable ASCII character, via a
table lookup. An encoded string is therefore longer than the original by
about 1/3.
If you wanted to encode a giant file, you could do it in large chunks that
are even multiples of 3 bytes, except for the last chunk, and append the outputs.
- Version:
- $Revision: 1.3 $
- Author:
- Last modified by $Author: CMitu $
Method Summary |
static byte[] |
decode(String aString)
Decodes a well-formed complete Base64 string back into an array of bytes.
|
static String |
encode(byte[] bytes)
Encode an arbitrary array of bytes as Base64 printable ASCII.
|
static void |
setLineLength(int length)
Determines how long the lines are that are generated by encode.
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Base64
public Base64()
encode
public static String encode(byte[] bytes)
- Encode an arbitrary array of bytes as Base64 printable ASCII.
It will be broken into lines of
#lineLength
characters each.
The last line is not terminated with a line separator.
The output will always have an even multiple of data characters,
exclusive of \n. It is padded out with =.
- Parameters:
bytes
- The bytes to encode- Returns:
- encoded string
decode
public static byte[] decode(String aString)
- Decodes a well-formed complete Base64 string back into an array of bytes.
It must have an even multiple of 4 data characters (not counting \n),
padded out with = as needed.
- Parameters:
aString
- The BASE64-encoded string to decode.- Returns:
- decided byte array
setLineLength
public static void setLineLength(int length)
- Determines how long the lines are that are generated by encode.
Ignored by decode.
- Parameters:
length
- 0 means no newlines inserted. length must be a multiple of 4.