- 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 ofBinaryCodecbased onalphabetof 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 StringdoEncode(byte[] data, BaseFormat format)Stringencode(byte[] data)StringgetAlphabet()abstract booleanisCaseSensitive()StringtoString()BinaryCodecwithFormat(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:
trueif case-sensitive (e.g. both 'a' and 'A' are used with different meanings),falseotherwise (the case of Latin Ascii letters will be ignored).
-
encode
public final String encode(byte[] data)
- Specified by:
encodein interfaceBinaryCodec- Parameters:
data- the binary data to encode.- Returns:
- the given
dataencoded asString.
-
doEncode
protected abstract String doEncode(byte[] data, BaseFormat format)
- Parameters:
data- the binary data to encode. Neithernullnor empty.format- theBaseFormatto configure the encoding.- Returns:
- the given
dataencoded asString.
-
decode
public final byte[] decode(String encodedData)
- Specified by:
decodein interfaceBinaryCodec- Parameters:
encodedData- theencodedString.- Returns:
- the decoded data as
bytearray.
-
doDecode
protected abstract byte[] doDecode(String encodedData, BaseFormat format)
- Parameters:
encodedData- theencodedString. Neithernullnorempty.format- theBaseFormatto configure the decoding.- Returns:
- the decoded data as
bytearray.
-
withFormat
public BinaryCodec withFormat(BaseFormat format)
- Parameters:
format- theBaseFormat.- Returns:
- the new
BinaryCodecwith the givenBaseFormatapplied.
-
-