public class Base64Encoder extends java.lang.Object implements StringCodec
Despite there being a gazillion other Base64 implementations out there, this has been written as part of XStream as it forms a core part but is too trivial to warrant an extra dependency. Recent Java Runtimes (since Java 6) provide an own Base64 codec though.
By default it will not insert line breaks to support Base64 values also as attribute values. However, the standard as described in RFC 1521, section 5.2 requires line breaks, allowing other Base64 tools to manipulate the data. You can configure the Base64Encoder to be RFC compliant.
Modifier and Type | Field and Description |
---|---|
private boolean |
lineBreaks |
private static int[] |
REVERSE_MAPPING |
private static char[] |
SIXTY_FOUR_CHARS |
Constructor and Description |
---|
Base64Encoder()
Constructs a Base64Encoder.
|
Base64Encoder(boolean lineBreaks)
Constructs a Base64Encoder.
|
Modifier and Type | Method and Description |
---|---|
(package private) int |
computeResultingStringSize(byte[] input) |
byte[] |
decode(java.lang.String input)
Decode the provided encoded string.
|
java.lang.String |
encode(byte[] input)
Encode the provided data.
|
private int |
mapCharToInt(java.io.Reader input) |
private static final char[] SIXTY_FOUR_CHARS
private static final int[] REVERSE_MAPPING
private final boolean lineBreaks
public Base64Encoder()
The encoder will not insert any line breaks.
public Base64Encoder(boolean lineBreaks)
lineBreaks
- flag to insert line breakspublic java.lang.String encode(byte[] input)
StringCodec
encode
in interface StringCodec
input
- the data to encodeint computeResultingStringSize(byte[] input)
public byte[] decode(java.lang.String input)
StringCodec
decode
in interface StringCodec
input
- the encoded stringprivate int mapCharToInt(java.io.Reader input) throws java.io.IOException
java.io.IOException