Class Base64Encoder
- java.lang.Object
-
- com.thoughtworks.xstream.core.util.Base64Encoder
-
- All Implemented Interfaces:
StringCodec
public class Base64Encoder extends java.lang.Object implements 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
Fields Modifier and Type Field Description private boolean
lineBreaks
private static int[]
REVERSE_MAPPING
private static char[]
SIXTY_FOUR_CHARS
-
Constructor Summary
Constructors Constructor Description Base64Encoder()
Constructs a Base64Encoder.Base64Encoder(boolean lineBreaks)
Constructs a Base64Encoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
Method Detail
-
encode
public java.lang.String encode(byte[] input)
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
public byte[] decode(java.lang.String input)
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
private int mapCharToInt(java.io.Reader input) throws java.io.IOException
- Throws:
java.io.IOException
-
-