- java.lang.Object
-
- io.github.mmm.binary.codec.Base
-
- All Implemented Interfaces:
BinaryCodec
- Direct Known Subclasses:
BaseGeneric
public abstract class Base extends Object implements BinaryCodec
Implementation ofBinaryCodec
based onalphabet
of unique and visible ASCII characters.- Since:
- 1.0.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description byte[]
decode(String encodedData)
protected abstract byte[]
doDecode(String encodedData, BaseFormat format)
protected abstract String
doEncode(byte[] data, BaseFormat format)
String
encode(byte[] data)
String
getAlphabet()
abstract boolean
isCaseSensitive()
String
toString()
BinaryCodec
withFormat(BaseFormat format)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.binary.codec.BinaryCodec
decodeInt, decodeLong, decodeShort, encodeInt, encodeLong, encodeShort
-
-
-
-
Method Detail
-
getAlphabet
public String getAlphabet()
- Returns:
- the alphabet of characters used to encode/decode the data. It shall only contain visible and regular ASCII characters and no duplicates. It is expected that characters are in a logical order (e.g. "0123456789" or "abcdef" rather than "5192" or "xazb").
-
isCaseSensitive
public abstract boolean isCaseSensitive()
- Returns:
true
if case-sensitive (e.g. both 'a' and 'A' are used with different meanings),false
otherwise (the case of Latin Ascii letters will be ignored).
-
encode
public final String encode(byte[] data)
- Specified by:
encode
in interfaceBinaryCodec
- Parameters:
data
- the binary data to encode.- Returns:
- the given
data
encoded asString
.
-
doEncode
protected abstract String doEncode(byte[] data, BaseFormat format)
- Parameters:
data
- the binary data to encode. Neithernull
nor empty.format
- theBaseFormat
to configure the encoding.- Returns:
- the given
data
encoded asString
.
-
decode
public final byte[] decode(String encodedData)
- Specified by:
decode
in interfaceBinaryCodec
- Parameters:
encodedData
- theencoded
String
.- Returns:
- the decoded data as
byte
array.
-
doDecode
protected abstract byte[] doDecode(String encodedData, BaseFormat format)
- Parameters:
encodedData
- theencoded
String
. Neithernull
norempty
.format
- theBaseFormat
to configure the decoding.- Returns:
- the decoded data as
byte
array.
-
withFormat
public BinaryCodec withFormat(BaseFormat format)
- Parameters:
format
- theBaseFormat
.- Returns:
- the new
BinaryCodec
with the givenBaseFormat
applied.
-
-