Class AbstractMagicBytesTransmission
java.lang.Object
org.refcodes.serial.AbstractMagicBytesTransmission
- All Implemented Interfaces:
Serializable, AliasAccessor, EncodingAccessor<Charset>, LengthAccessor, MagicBytesAccessor, MagicBytesAccessor.MagicBytesMutator, MagicBytesAccessor.MagicBytesProperty, PayloadAccessor<byte[]>, PayloadAccessor.PayloadBuilder<byte[], PayloadTransmission<byte[]>>, PayloadAccessor.PayloadMutator<byte[]>, PayloadAccessor.PayloadProperty<byte[]>, Resetable, Diagnosable, Schemable<DiagnosticOptions>, 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, 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 AliasAccessor
AliasAccessor.AliasBuilder<B>, AliasAccessor.AliasMutator, AliasAccessor.AliasPropertyNested classes/interfaces inherited from interface EncodingAccessor
EncodingAccessor.EncodingBuilder<E,B>, EncodingAccessor.EncodingMutator<E>, EncodingAccessor.EncodingProperty<E> Nested classes/interfaces inherited from interface LengthAccessor
LengthAccessor.LengthBuilder<B>, LengthAccessor.LengthMutator, LengthAccessor.LengthPropertyNested classes/interfaces inherited from interface MagicBytesAccessor
MagicBytesAccessor.MagicBytesBuilder<B>, MagicBytesAccessor.MagicBytesMutator, MagicBytesAccessor.MagicBytesPropertyNested classes/interfaces inherited from interface MagicBytesAccessor
MagicBytesAccessor.MagicBytesBuilder<B>, MagicBytesAccessor.MagicBytesMutator, MagicBytesAccessor.MagicBytesPropertyNested classes/interfaces inherited from interface MagicBytesLengthAccessor
MagicBytesLengthAccessor.MagicBytesLengthBuilder<B>, MagicBytesLengthAccessor.MagicBytesLengthMutator, MagicBytesLengthAccessor.MagicBytesLengthPropertyNested classes/interfaces inherited from interface PayloadAccessor
PayloadAccessor.PayloadBuilder<P,B>, PayloadAccessor.PayloadMutator<P>, PayloadAccessor.PayloadProperty<P> Nested classes/interfaces inherited from interface 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.Returns theImmutableSimpleTypeTablerepresentation of thisTransmission.toString()Methods inherited from interface MagicBytesAccessor
toMagicBytes, toMagicBytesMethods inherited from interface MagicBytesAccessor.MagicBytesProperty
letMagicBytes, letMagicBytesMethods inherited from interface MagicBytesAccessor.MagicBytesProperty
letMagicBytesMethods inherited from interface PayloadAccessor
getPayloadOrMethods inherited from interface PayloadAccessor.PayloadBuilder
withPayloadMethods inherited from interface PayloadAccessor.PayloadProperty
letPayloadMethods inherited from interface Transmission
getLength, transmitTo, transmitToMethods inherited from interface Transmission.TransmissionMixin
transmitTo
-
Field Details
-
_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 interfacePayloadAccessor.PayloadMutator<byte[]>
-
getAlias
- Specified by:
getAliasin interfaceAliasAccessor
-
getMagicBytes
public byte[] getMagicBytes()Returns the magic bytes as stored by this instance.- Specified by:
getMagicBytesin interfaceMagicBytesAccessor- Returns:
- The according magic bytes.
-
setMagicBytes
public void setMagicBytes(byte[] aMagicBytes) Sets the magic bytes to be stored by this instance.- Specified by:
setMagicBytesin interfaceMagicBytesAccessor.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 interfaceMagicBytesAccessor.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.- Specified by:
setMagicBytesin interfaceMagicBytesAccessor.MagicBytesMutator- Parameters:
aMagicBytes- The String from which to copy the according magic bytes from.aCharset- TheCharsetto use when converting theStringto a byte array.
-
toMagicBytesString
-
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 interfacePayloadAccessor<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 interfaceResetable- Specified by:
resetin interfaceTransmission
-
toSchema
- Specified by:
toSchemain interfaceSchemable<DiagnosticOptions>
-
getEncoding
- Specified by:
getEncodingin interfaceEncodingAccessor<Charset>
-
toString
-
hashCode
-
equals
-
toSimpleTypeTable
Returns theImmutableSimpleTypeTablerepresentation of thisTransmission. In case this Transmission hasTransmissionchildren, then the children are queried as well and contained in the resultingImmutableSimpleTypeTable. The aliases of the accordingTransmissioninstances represent the resulting path to aTransmission's final simple type.- Specified by:
toSimpleTypeTablein interfaceTransmission- Returns:
- The
ImmutableSimpleTypeTablerepresenting thisTransmissionand (if any) its children, with the according aliases forming the paths to theTransmission's values.
-