- java.lang.Object
-
- org.refcodes.serial.AbstractMagicBytesTransmission
-
- All Implemented Interfaces:
Serializable
,org.refcodes.mixin.AliasAccessor
,org.refcodes.mixin.EncodingAccessor<Charset>
,org.refcodes.mixin.LengthAccessor
,org.refcodes.mixin.MagicBytesAccessor
,org.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator
,org.refcodes.mixin.MagicBytesAccessor.MagicBytesProperty
,org.refcodes.mixin.PayloadAccessor<byte[]>
,org.refcodes.mixin.PayloadAccessor.PayloadBuilder<byte[],PayloadTransmission<byte[]>>
,org.refcodes.mixin.PayloadAccessor.PayloadMutator<byte[]>
,org.refcodes.mixin.PayloadAccessor.PayloadProperty<byte[]>
,MagicBytesAccessor
,MagicBytesAccessor.MagicBytesMutator
,MagicBytesAccessor.MagicBytesProperty
,MagicBytesLengthAccessor
,PayloadTransmission<byte[]>
,Transmission
,Transmission.TransmissionMixin
- Direct Known Subclasses:
AbstractMagicBytesTransmissionDecorator
,MagicBytesSegment
public abstract class AbstractMagicBytesTransmission extends Object implements PayloadTransmission<byte[]>, Transmission.TransmissionMixin, MagicBytesAccessor.MagicBytesProperty, MagicBytesLengthAccessor, org.refcodes.mixin.EncodingAccessor<Charset>
Magic bytes are usually found (somewhere) at the beginning of a file or a stream. AAbstractMagicBytesTransmission
provides the base functionality to manage magic bytes.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.AliasAccessor
org.refcodes.mixin.AliasAccessor.AliasBuilder<B extends org.refcodes.mixin.AliasAccessor.AliasBuilder<B>>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.EncodingAccessor
org.refcodes.mixin.EncodingAccessor.EncodingBuilder<E extends Object,B extends org.refcodes.mixin.EncodingAccessor.EncodingBuilder<E,B>>, org.refcodes.mixin.EncodingAccessor.EncodingMutator<E extends Object>, org.refcodes.mixin.EncodingAccessor.EncodingProperty<E extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.LengthAccessor
org.refcodes.mixin.LengthAccessor.LengthBuilder<B extends org.refcodes.mixin.LengthAccessor.LengthBuilder<B>>, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.MagicBytesAccessor
org.refcodes.mixin.MagicBytesAccessor.MagicBytesBuilder<B extends org.refcodes.mixin.MagicBytesAccessor.MagicBytesBuilder<B>>, org.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator, org.refcodes.mixin.MagicBytesAccessor.MagicBytesProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.MagicBytesAccessor
MagicBytesAccessor.MagicBytesBuilder<B extends MagicBytesAccessor.MagicBytesBuilder<B>>, MagicBytesAccessor.MagicBytesMutator, MagicBytesAccessor.MagicBytesProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.MagicBytesLengthAccessor
MagicBytesLengthAccessor.MagicBytesLengthBuilder<B extends MagicBytesLengthAccessor.MagicBytesLengthBuilder<B>>, MagicBytesLengthAccessor.MagicBytesLengthMutator, MagicBytesLengthAccessor.MagicBytesLengthProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.PayloadAccessor
org.refcodes.mixin.PayloadAccessor.PayloadBuilder<P extends Object,B extends org.refcodes.mixin.PayloadAccessor.PayloadBuilder<P,B>>, org.refcodes.mixin.PayloadAccessor.PayloadMutator<P extends Object>, org.refcodes.mixin.PayloadAccessor.PayloadProperty<P extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Field Summary
Fields Modifier and Type Field Description protected String
_alias
protected String
_charset
protected byte[]
_magicBytes
protected int
_magicBytesLength
static String
MAGIC_BYTES
static String
MAGIC_BYTES_TEXT
-
Constructor Summary
Constructors Constructor Description AbstractMagicBytesTransmission(String aAlias, byte[] aMagicBytes)
Constructs anAbstractMagicBytesTransmission
with the according magic bytes.AbstractMagicBytesTransmission(String aAlias, byte[] aMagicBytes, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance for magic bytes of the given length.AbstractMagicBytesTransmission(String aAlias, int aMagicBytesLength)
Constructs anAbstractMagicBytesTransmission
for magic bytes of the given length.AbstractMagicBytesTransmission(String aAlias, String aMagicBytes)
Constructs anAbstractMagicBytesTransmission
with the according magic bytes (retrieved from the givenString
).AbstractMagicBytesTransmission(String aAlias, String aMagicBytes, Charset aCharset)
Constructs anAbstractMagicBytesTransmission
with the according magic bytes (retrieved from the givenString
).AbstractMagicBytesTransmission(String aAlias, String aMagicBytes, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance for magic bytes of the given length.AbstractMagicBytesTransmission(String aAlias, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance for magic bytes of the given length.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
String
getAlias()
Charset
getEncoding()
byte[]
getMagicBytes()
Returns the magic bytes as stored by this instance.int
getMagicBytesLength()
Retrieves the magic bytes length from the magic bytes magic bytes length property.byte[]
getPayload()
Returns the magic bytes as ofgetMagicBytes()
.int
hashCode()
void
setMagicBytes(byte[] aMagicBytes)
Sets the magic bytes to be stored by this instance.void
setMagicBytes(String aMagicBytes)
Sets the magic bytes from the providedString
to be stored by this instance (uses theTransmissionMetrics.DEFAULT_ENCODING
) for byte conversion).void
setMagicBytes(String aMagicBytes, Charset aCharset)
Sets the magic bytes from the providedString
to be stored by this instance.void
setPayload(byte[] aValue)
Sets the magic bytes as ofsetMagicBytes(byte[])
.String
toMagicBytesString()
Retrieves theString
representation of the given magic bytes using the latest providedCharset
for conversion or theTransmissionMetrics.DEFAULT_ENCODING
in case noCharset
has been provided.String
toMagicBytesString(String aCharset)
Retrieves theString
representation of the given magic bytes using the providedCharset
for conversion or theTransmissionMetrics.DEFAULT_ENCODING
in case noCharset
has been provided.Schema
toSchema()
Retrieves theSchema
representing theTransmission
.Sequence
toSequence()
Provides theSequence
representation of thisTransmission
.org.refcodes.struct.SimpleTypeMap
toSimpleTypeMap()
Returns theSimpleTypeMap
representation of thisTransmission
.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.serial.MagicBytesAccessor
toMagicBytes, toMagicBytes
-
Methods inherited from interface org.refcodes.mixin.MagicBytesAccessor.MagicBytesProperty
letMagicBytes, letMagicBytes
-
Methods inherited from interface org.refcodes.serial.MagicBytesAccessor.MagicBytesProperty
letMagicBytes
-
Methods inherited from interface org.refcodes.serial.Transmission
getLength, transmitTo, transmitTo
-
Methods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitTo
-
-
-
-
Field Detail
-
MAGIC_BYTES
public static final String MAGIC_BYTES
- See Also:
- Constant Field Values
-
MAGIC_BYTES_TEXT
public static final String MAGIC_BYTES_TEXT
- See Also:
- Constant Field Values
-
_magicBytes
protected byte[] _magicBytes
-
_magicBytesLength
protected int _magicBytesLength
-
_charset
protected String _charset
-
_alias
protected String _alias
-
-
Constructor Detail
-
AbstractMagicBytesTransmission
public AbstractMagicBytesTransmission(String aAlias, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance for magic bytes of the given length. The configuration attributes are taken from theTransmissionMetrics
configuration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aAlias
- The alias which identifies the content of this segment.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
AbstractMagicBytesTransmission
public AbstractMagicBytesTransmission(String aAlias, String aMagicBytes, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance for magic bytes of the given length. The configuration attributes are taken from theTransmissionMetrics
configuration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aAlias
- The alias which identifies the content of this segment.aMagicBytes
- TheString
to be stored by this instance as magic bytes.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
AbstractMagicBytesTransmission
public AbstractMagicBytesTransmission(String aAlias, byte[] aMagicBytes, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance for magic bytes of the given length. The configuration attributes are taken from theTransmissionMetrics
configuration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aAlias
- The alias which identifies the content of this segment.aMagicBytes
- The bytes to be stored by this instance as magic bytes.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
AbstractMagicBytesTransmission
public AbstractMagicBytesTransmission(String aAlias, int aMagicBytesLength)
Constructs anAbstractMagicBytesTransmission
for magic bytes of the given length.- Parameters:
aAlias
- The alias which identifies the content of this segment.aMagicBytesLength
- The length of the magic bytes sequence.
-
AbstractMagicBytesTransmission
public AbstractMagicBytesTransmission(String aAlias, String aMagicBytes)
Constructs anAbstractMagicBytesTransmission
with the according magic bytes (retrieved from the givenString
).- Parameters:
aAlias
- The alias which identifies the content of this segment.aMagicBytes
- TheString
to be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING
) for byte conversion).
-
AbstractMagicBytesTransmission
public AbstractMagicBytesTransmission(String aAlias, String aMagicBytes, Charset aCharset)
Constructs anAbstractMagicBytesTransmission
with the according magic bytes (retrieved from the givenString
).
-
AbstractMagicBytesTransmission
public AbstractMagicBytesTransmission(String aAlias, byte[] aMagicBytes)
Constructs anAbstractMagicBytesTransmission
with the according magic bytes.- Parameters:
aAlias
- The alias which identifies the content of this segment.aMagicBytes
- The magic bytes to be stored by this instance.
-
-
Method Detail
-
setPayload
public void setPayload(byte[] aValue)
Sets the magic bytes as ofsetMagicBytes(byte[])
.- Specified by:
setPayload
in interfaceorg.refcodes.mixin.PayloadAccessor.PayloadMutator<byte[]>
-
getAlias
public String getAlias()
- Specified by:
getAlias
in interfaceorg.refcodes.mixin.AliasAccessor
-
getMagicBytes
public byte[] getMagicBytes()
Returns the magic bytes as stored by this instance.- Specified by:
getMagicBytes
in interfaceorg.refcodes.mixin.MagicBytesAccessor
- Returns:
- The according magic bytes.
-
setMagicBytes
public void setMagicBytes(byte[] aMagicBytes)
Sets the magic bytes to be stored by this instance.- Specified by:
setMagicBytes
in interfaceorg.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator
- Parameters:
aMagicBytes
- The according magic bytes to store.
-
setMagicBytes
public void setMagicBytes(String aMagicBytes)
Sets the magic bytes from the providedString
to be stored by this instance (uses theTransmissionMetrics.DEFAULT_ENCODING
) for byte conversion).- Specified by:
setMagicBytes
in interfaceorg.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator
- Specified by:
setMagicBytes
in interfaceMagicBytesAccessor.MagicBytesMutator
- Parameters:
aMagicBytes
- The String from which to copy the according magic bytes from.
-
setMagicBytes
public void setMagicBytes(String aMagicBytes, Charset aCharset)
Sets the magic bytes from the providedString
to be stored by this instance.
-
toMagicBytesString
public String toMagicBytesString()
Retrieves theString
representation of the given magic bytes using the latest providedCharset
for conversion or theTransmissionMetrics.DEFAULT_ENCODING
in case noCharset
has been provided.- Returns:
- The
String
representation of the magic bytes.
-
toMagicBytesString
public String toMagicBytesString(String aCharset)
Retrieves theString
representation of the given magic bytes using the providedCharset
for conversion or theTransmissionMetrics.DEFAULT_ENCODING
in case noCharset
has been provided.
-
toSequence
public Sequence toSequence()
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmission
instances) may be backed by the returnedSequence
.- Specified by:
toSequence
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
getMagicBytesLength
public int getMagicBytesLength()
Retrieves the magic bytes length from the magic bytes magic bytes length property.- Specified by:
getMagicBytesLength
in interfaceMagicBytesLengthAccessor
- Returns:
- The magic bytes length stored by the magic bytes magic bytes length property.
-
getPayload
public byte[] getPayload()
Returns the magic bytes as ofgetMagicBytes()
.- Specified by:
getPayload
in interfaceorg.refcodes.mixin.PayloadAccessor<byte[]>
-
toSchema
public Schema toSchema()
Retrieves theSchema
representing theTransmission
. Retrieving aSchema
is useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegment
instance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment
.- Specified by:
toSchema
in interfaceTransmission
- Returns:
- The
Schema
representation of the implementing type for debugging and verification (or documentation) purposes.
-
getEncoding
public Charset getEncoding()
- Specified by:
getEncoding
in interfaceorg.refcodes.mixin.EncodingAccessor<Charset>
-
toSimpleTypeMap
public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
Returns theSimpleTypeMap
representation of thisTransmission
. In case this Transmission hasTransmission
children, then the children are queried as well and contained in the resultingSimpleTypeMap
. The aliases of the accordingTransmission
instances represent the resulting path to aTransmission
's final simple type.- Specified by:
toSimpleTypeMap
in interfaceTransmission
- Returns:
- The
SimpleTypeMap
representing thisTransmission
and (if any) its children, with the according aliases forming the paths to theTransmission
's values.
-
-