-
- All Superinterfaces:
Streamable
- All Known Subinterfaces:
SignatureWithPublicKeyRecovery
- All Known Implementing Classes:
BinaryType,CryptoBinary,EncryptedData,Hash,SignatureBinary,SignatureEcBc,SignatureEcBcPlain,SignatureEcBcWithRecoveryId,SignatureGeneric,SignatureRsa
public interface Binary extends Streamable
Interface for smaller binary data (e.g. a cryptographic signature). Implementations shall be immutable.
Attention:
This API is designed for smaller binary data and will cause it to be fully loaded into memory (Java heap). For binary large objects (BLOB) (e.g. for generic files or documents) use other solutions like e.g.Blob.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]EMPTY_BYTE_ARRAYAn empty byte array (no data).
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Stringformat(BinaryCodec codec)This method avoids anarray-copyofgetData()and is therefore more efficient than usingBinaryCodec.encode(getData()).
ATTENTION:
Sub-types often represent sensible data.default StringformatBase64()ATTENTION:
Sub-types often represent sensible data.default StringformatHex()ATTENTION:
Sub-types often represent sensible data.byte[]getData()ATTENTION:
Sub-types often represent sensible data.voidgetData(byte[] buffer, int offset)Copies thedatainto the given buffer.bytegetDataByte(int index)intgetLength()booleanisZeros()-
Methods inherited from interface io.github.mmm.binary.Streamable
asStream, save
-
-
-
-
Method Detail
-
getDataByte
byte getDataByte(int index)
-
getData
byte[] getData()
ATTENTION:
Sub-types often represent sensible data. Be careful to pass these data in raw form (unencrypted).- Returns:
- the raw encoded data. Array will be copied to prevent manipulation. Hence, this method is expensive and subsequent calls shall be avoided.
-
getData
void getData(byte[] buffer, int offset)Copies thedatainto the given buffer.- Parameters:
buffer- the byte array to copy the data to. Has to have enough capacity left for thelengthof this BLOB.offset- the index where to start copying tobuffer.
-
getLength
int getLength()
- Returns:
- the length of this BLOB in bytes (array length of
getData()).
-
format
String format(BinaryCodec codec)
This method avoids anarray-copyofgetData()and is therefore more efficient than usingBinaryCodec.encode(getData()).
ATTENTION:
Sub-types often represent sensible data. Be careful to pass the data in raw form (unencrypted).- Parameters:
codec- theBinaryCodec.- Returns:
- the
encodeddata.
-
formatHex
default String formatHex()
ATTENTION:
Sub-types often represent sensible data. Be careful to pass the data in raw form (unencrypted).- Returns:
- a hex-dump of this BLOB. This form is more transparent but less compact to
base 64 representation.
-
formatBase64
default String formatBase64()
ATTENTION:
Sub-types often represent sensible data. Be careful to pass the data in raw form (unencrypted).
-
isZeros
boolean isZeros()
- Returns:
trueif thedatacontains only zeros (0values),falseotherwise.
-
-