Class Base64Encoder
java.lang.Object
com.thoughtworks.xstream.core.util.Base64Encoder
- All Implemented Interfaces:
StringCodec
Encodes binary data to plain text as Base64.
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private static final int[]
private static final char[]
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a Base64Encoder.Base64Encoder
(boolean lineBreaks) Constructs a Base64Encoder. -
Method Summary
Modifier and TypeMethodDescription(package private) int
computeResultingStringSize
(byte[] input) byte[]
Decode the provided encoded string.encode
(byte[] input) Encode the provided data.private int
mapCharToInt
(Reader input)
-
Field Details
-
SIXTY_FOUR_CHARS
private static final char[] SIXTY_FOUR_CHARS -
REVERSE_MAPPING
private static final int[] REVERSE_MAPPING -
lineBreaks
private final boolean lineBreaks
-
-
Constructor Details
-
Base64Encoder
public Base64Encoder()Constructs a Base64Encoder.The encoder will not insert any line breaks.
- Since:
- 1.4.11
-
Base64Encoder
public Base64Encoder(boolean lineBreaks) Constructs a Base64Encoder.- Parameters:
lineBreaks
- flag to insert line breaks- Since:
- 1.4.11
-
-
Method Details
-
encode
Description copied from interface:StringCodec
Encode the provided data.- Specified by:
encode
in interfaceStringCodec
- Parameters:
input
- the data to encode- Returns:
- the data encoded as string
-
computeResultingStringSize
int computeResultingStringSize(byte[] input) -
decode
Description copied from interface:StringCodec
Decode the provided encoded string.- Specified by:
decode
in interfaceStringCodec
- Parameters:
input
- the encoded string- Returns:
- the decoded data
-
mapCharToInt
- Throws:
IOException
-