Class AbstractMagicBytesTransmission

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.Schemable<SerialSchema>, 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:
  • Field Details

    • MAGIC_BYTES

      public static final String MAGIC_BYTES
      See Also:
    • MAGIC_BYTES_TEXT

      public static final String MAGIC_BYTES_TEXT
      See Also:
    • _magicBytes

      protected byte[] _magicBytes
    • _magicBytesLength

      protected int _magicBytesLength
    • _charset

      protected String _charset
    • _alias

      protected String _alias
  • Constructor Details

    • AbstractMagicBytesTransmission

      public AbstractMagicBytesTransmission(String aAlias, TransmissionMetrics aTransmissionMetrics)
      Constructs an according instance for magic bytes of the given length. The configuration attributes are taken from the TransmissionMetrics 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 - The TransmissionMetrics 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 the TransmissionMetrics 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 String to be stored by this instance as magic bytes.
      aTransmissionMetrics - The TransmissionMetrics 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 the TransmissionMetrics 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 - The TransmissionMetrics to be used for configuring this instance.
    • AbstractMagicBytesTransmission

      public AbstractMagicBytesTransmission(String aAlias, int aMagicBytesLength)
      Constructs an AbstractMagicBytesTransmission 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 an AbstractMagicBytesTransmission with the according magic bytes (retrieved from the given String).
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aMagicBytes - The String to be stored by this instance as magic bytes (uses the TransmissionMetrics.DEFAULT_ENCODING) for byte conversion).
    • AbstractMagicBytesTransmission

      public AbstractMagicBytesTransmission(String aAlias, String aMagicBytes, Charset aCharset)
      Constructs an AbstractMagicBytesTransmission with the according magic bytes (retrieved from the given String).
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aMagicBytes - The String to be stored by this instance as magic bytes.
      aCharset - The Charset to use when converting the String to a byte array.
    • AbstractMagicBytesTransmission

      public AbstractMagicBytesTransmission(String aAlias, byte[] aMagicBytes)
      Constructs an AbstractMagicBytesTransmission 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 Details

    • setPayload

      public void setPayload(byte[] aValue)
      Sets the magic bytes as of setMagicBytes(byte[]).
      Specified by:
      setPayload in interface org.refcodes.mixin.PayloadAccessor.PayloadMutator<byte[]>
    • getAlias

      public String getAlias()
      Specified by:
      getAlias in interface org.refcodes.mixin.AliasAccessor
    • getMagicBytes

      public byte[] getMagicBytes()
      Returns the magic bytes as stored by this instance.
      Specified by:
      getMagicBytes in interface org.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 interface org.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator
      Parameters:
      aMagicBytes - The according magic bytes to store.
    • setMagicBytes

      public void setMagicBytes(String aMagicBytes)
      Sets the magic bytes from the provided String to be stored by this instance (uses the TransmissionMetrics.DEFAULT_ENCODING) for byte conversion).
      Specified by:
      setMagicBytes in interface org.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator
      Specified by:
      setMagicBytes in interface MagicBytesAccessor.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 provided String to be stored by this instance.
      Specified by:
      setMagicBytes in interface org.refcodes.mixin.MagicBytesAccessor.MagicBytesMutator
      Parameters:
      aMagicBytes - The String from which to copy the according magic bytes from.
      aCharset - The Charset to use when converting the String to a byte array.
    • toMagicBytesString

      public String toMagicBytesString()
      Retrieves the String representation of the given magic bytes using the latest provided Charset for conversion or the TransmissionMetrics.DEFAULT_ENCODING in case no Charset has been provided.
      Returns:
      The String representation of the magic bytes.
    • toMagicBytesString

      public String toMagicBytesString(String aCharset)
      Retrieves the String representation of the given magic bytes using the provided Charset for conversion or the TransmissionMetrics.DEFAULT_ENCODING in case no Charset has been provided.
      Parameters:
      aCharset - The Charset to use when converting the String to a byte array.
      Returns:
      The String representation of the magic bytes.
    • toSequence

      public Sequence toSequence()
      Provides the Sequence representation of this Transmission. In case of nested Transmission instances, all Sequence representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nested Transmission instances) may be backed by the returned Sequence.
      Specified by:
      toSequence in interface Transmission
      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 interface MagicBytesLengthAccessor
      Returns:
      The magic bytes length stored by the magic bytes magic bytes length property.
    • getPayload

      public byte[] getPayload()
      Returns the magic bytes as of getMagicBytes().
      Specified by:
      getPayload in interface org.refcodes.mixin.PayloadAccessor<byte[]>
    • toSchema

      public SerialSchema toSchema()
      Retrieves the SerialSchema representing the Transmission. Retrieving a SerialSchema is useful when analyzing and debugging data structures such as a AllocSectionDecoratorSegment instance to help document, learn and verify on the structure (as well as the content) of that very AllocSectionDecoratorSegment.
      Specified by:
      toSchema in interface org.refcodes.mixin.Schemable<SerialSchema>
      Specified by:
      toSchema in interface Transmission
      Returns:
      The SerialSchema representation of the implementing type for debugging and verification (or documentation) purposes.
    • getEncoding

      public Charset getEncoding()
      Specified by:
      getEncoding in interface org.refcodes.mixin.EncodingAccessor<Charset>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toSimpleTypeMap

      public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
      Returns the SimpleTypeMap representation of this Transmission. In case this Transmission has Transmission children, then the children are queried as well and contained in the resulting SimpleTypeMap. The aliases of the according Transmission instances represent the resulting path to a Transmission's final simple type.
      Specified by:
      toSimpleTypeMap in interface Transmission
      Returns:
      The SimpleTypeMap representing this Transmission and (if any) its children, with the according aliases forming the paths to the Transmission's values.