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[]>,org.refcodes.mixin.Resetable,org.refcodes.schema.Schemable,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. A
AbstractMagicBytesTransmission provides the base
functionality to manage magic bytes.- See Also:
-
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.AliasPropertyNested 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.LengthPropertyNested 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.MagicBytesPropertyNested classes/interfaces inherited from interface org.refcodes.serial.MagicBytesAccessor
MagicBytesAccessor.MagicBytesBuilder<B extends MagicBytesAccessor.MagicBytesBuilder<B>>, MagicBytesAccessor.MagicBytesMutator, MagicBytesAccessor.MagicBytesPropertyNested classes/interfaces inherited from interface org.refcodes.serial.MagicBytesLengthAccessor
MagicBytesLengthAccessor.MagicBytesLengthBuilder<B extends MagicBytesLengthAccessor.MagicBytesLengthBuilder<B>>, MagicBytesLengthAccessor.MagicBytesLengthMutator, MagicBytesLengthAccessor.MagicBytesLengthPropertyNested 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 -
Constructor Summary
ConstructorsConstructorDescriptionAbstractMagicBytesTransmission(String aAlias, byte[] aMagicBytes) Constructs anAbstractMagicBytesTransmissionwith 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 anAbstractMagicBytesTransmissionfor magic bytes of the given length.AbstractMagicBytesTransmission(String aAlias, String aMagicBytes) Constructs anAbstractMagicBytesTransmissionwith the according magic bytes (retrieved from the givenString).AbstractMagicBytesTransmission(String aAlias, String aMagicBytes, Charset aCharset) Constructs anAbstractMagicBytesTransmissionwith 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
Modifier and TypeMethodDescriptionbooleangetAlias()byte[]Returns the magic bytes as stored by this instance.intRetrieves the magic bytes length from the magic bytes magic bytes length property.byte[]Returns the magic bytes as ofgetMagicBytes().inthashCode()voidreset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!)voidsetMagicBytes(byte[] aMagicBytes) Sets the magic bytes to be stored by this instance.voidsetMagicBytes(String aMagicBytes) Sets the magic bytes from the providedStringto be stored by this instance (uses theTransmissionMetrics.DEFAULT_ENCODING) for byte conversion).voidsetMagicBytes(String aMagicBytes, Charset aCharset) Sets the magic bytes from the providedStringto be stored by this instance.voidsetPayload(byte[] aValue) Sets the magic bytes as ofsetMagicBytes(byte[]).Retrieves theStringrepresentation of the given magic bytes using the latest providedCharsetfor conversion or theTransmissionMetrics.DEFAULT_ENCODINGin case noCharsethas been provided.toMagicBytesString(String aCharset) Retrieves theStringrepresentation of the given magic bytes using the providedCharsetfor conversion or theTransmissionMetrics.DEFAULT_ENCODINGin case noCharsethas been provided.toSchema()Provides theSequencerepresentation of thisTransmission.org.refcodes.struct.SimpleTypeMapReturns theSimpleTypeMaprepresentation of thisTransmission.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.refcodes.serial.MagicBytesAccessor
toMagicBytes, toMagicBytesMethods inherited from interface org.refcodes.mixin.MagicBytesAccessor.MagicBytesProperty
letMagicBytes, letMagicBytesMethods inherited from interface org.refcodes.serial.MagicBytesAccessor.MagicBytesProperty
letMagicBytesMethods inherited from interface org.refcodes.mixin.PayloadAccessor
getPayloadOrMethods inherited from interface org.refcodes.mixin.PayloadAccessor.PayloadBuilder
withPayloadMethods inherited from interface org.refcodes.mixin.PayloadAccessor.PayloadProperty
letPayloadMethods inherited from interface org.refcodes.serial.Transmission
getLength, transmitTo, transmitToMethods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitTo
-
Field Details
-
MAGIC_BYTES
- See Also:
-
MAGIC_BYTES_TEXT
- See Also:
-
_magicBytes
protected byte[] _magicBytes -
_magicBytesLength
protected int _magicBytesLength -
_charset
-
_alias
-
-
Constructor Details
-
AbstractMagicBytesTransmission
Constructs an according instance for magic bytes of the given length. The configuration attributes are taken from theTransmissionMetricsconfiguration 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- TheTransmissionMetricsto 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 theTransmissionMetricsconfiguration 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- TheStringto be stored by this instance as magic bytes.aTransmissionMetrics- TheTransmissionMetricsto 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 theTransmissionMetricsconfiguration 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- TheTransmissionMetricsto be used for configuring this instance.
-
AbstractMagicBytesTransmission
Constructs anAbstractMagicBytesTransmissionfor 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
Constructs anAbstractMagicBytesTransmissionwith the according magic bytes (retrieved from the givenString).- Parameters:
aAlias- The alias which identifies the content of this segment.aMagicBytes- TheStringto be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING) for byte conversion).
-
AbstractMagicBytesTransmission
Constructs anAbstractMagicBytesTransmissionwith the according magic bytes (retrieved from the givenString). -
AbstractMagicBytesTransmission
Constructs anAbstractMagicBytesTransmissionwith 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 Details
-
setPayload
public void setPayload(byte[] aValue) Sets the magic bytes as ofsetMagicBytes(byte[]).- Specified by:
setPayloadin interfaceorg.refcodes.mixin.PayloadAccessor.PayloadMutator<byte[]>
-
getAlias
- Specified by:
getAliasin interfaceorg.refcodes.mixin.AliasAccessor
-
getMagicBytes
public byte[] getMagicBytes()Returns the magic bytes as stored by this instance.- Specified by:
getMagicBytesin 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:
setMagicBytesin interfaceorg.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator- Parameters:
aMagicBytes- The according magic bytes to store.
-
setMagicBytes
Sets the magic bytes from the providedStringto be stored by this instance (uses theTransmissionMetrics.DEFAULT_ENCODING) for byte conversion).- Specified by:
setMagicBytesin interfaceorg.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator- Specified by:
setMagicBytesin interfaceMagicBytesAccessor.MagicBytesMutator- Parameters:
aMagicBytes- The String from which to copy the according magic bytes from.
-
setMagicBytes
Sets the magic bytes from the providedStringto be stored by this instance. -
toMagicBytesString
Retrieves theStringrepresentation of the given magic bytes using the latest providedCharsetfor conversion or theTransmissionMetrics.DEFAULT_ENCODINGin case noCharsethas been provided.- Returns:
- The
Stringrepresentation of the magic bytes.
-
toMagicBytesString
Retrieves theStringrepresentation of the given magic bytes using the providedCharsetfor conversion or theTransmissionMetrics.DEFAULT_ENCODINGin case noCharsethas been provided. -
toSequence
Provides theSequencerepresentation of thisTransmission. In case of nestedTransmissioninstances, allSequencerepresentations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmissioninstances) may be backed by the returnedSequence.- Specified by:
toSequencein 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:
getMagicBytesLengthin 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:
getPayloadin interfaceorg.refcodes.mixin.PayloadAccessor<byte[]>
-
reset
public void reset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!) reset any configurations or settings required to produce the dynamic data (e.g. theTransmissionMetrics).- Specified by:
resetin interfaceorg.refcodes.mixin.Resetable- Specified by:
resetin interfaceTransmission
-
toSchema
- Specified by:
toSchemain interfaceorg.refcodes.schema.Schemable- Specified by:
toSchemain interfaceTransmission
-
getEncoding
- Specified by:
getEncodingin interfaceorg.refcodes.mixin.EncodingAccessor<Charset>
-
toString
-
hashCode
public int hashCode() -
equals
-
toSimpleTypeMap
public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()Returns theSimpleTypeMaprepresentation of thisTransmission. In case this Transmission hasTransmissionchildren, then the children are queried as well and contained in the resultingSimpleTypeMap. The aliases of the accordingTransmissioninstances represent the resulting path to aTransmission's final simple type.- Specified by:
toSimpleTypeMapin interfaceTransmission- Returns:
- The
SimpleTypeMaprepresenting thisTransmissionand (if any) its children, with the according aliases forming the paths to theTransmission's values.
-