Class MagicBytesSegment
java.lang.Object
org.refcodes.serial.AbstractMagicBytesTransmission
org.refcodes.serial.MagicBytesSegment
- 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[]>, Segment, Segment.SegmentMixin, Transmission, Transmission.TransmissionMixin
- Direct Known Subclasses:
AssertMagicBytesSegment
public class MagicBytesSegment
extends AbstractMagicBytesTransmission
implements Segment.SegmentMixin, Segment
Magic bytes are usually found (somewhere) at the beginning of a file or a
stream. A
MagicBytesSegment decorates a Segment decoratee and
prefixes this Segment instance with given 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 Segment
Segment.SegmentMixinNested classes/interfaces inherited from interface Transmission
Transmission.TransmissionMixin -
Field Summary
Fields inherited from class AbstractMagicBytesTransmission
_alias, _charset, _magicBytes, _magicBytesLength -
Constructor Summary
ConstructorsConstructorDescriptionMagicBytesSegment(byte... aMagicBytes) Constructs an according instance with the according magic bytes.MagicBytesSegment(byte[] aMagicBytes, TransmissionMetrics aTransmissionMetrics) Constructs an according instance for magic bytes of the given length.MagicBytesSegment(int aMagicBytesLength) Constructs an according instance with magic bytes of the given length.MagicBytesSegment(String aMagicBytes) Constructs an according instance with the according magic bytes (retrieved from the givenString).MagicBytesSegment(String aAlias, byte... aMagicBytes) Instantiates the classMagicBytesSegment.MagicBytesSegment(String aAlias, byte[] aMagicBytes, TransmissionMetrics aTransmissionMetrics) Constructs an according instance for magic bytes of the given length.MagicBytesSegment(String aAlias, int aMagicBytesLength) Instantiates the classMagicBytesSegment.MagicBytesSegment(String aAlias, String aMagicBytes) Constructs an according instance with the according magic bytes (retrieved from the givenString).MagicBytesSegment(String aAlias, String aMagicBytes, Charset aCharset) Constructs an according instance with the according magic bytes (retrieved from the givenString).MagicBytesSegment(String aAlias, String aMagicBytes, TransmissionMetrics aTransmissionMetrics) Constructs an according instance for magic bytes of the given length.MagicBytesSegment(String aMagicBytes, Charset aCharset) Constructs an according instance with the according magic bytes (retrieved from the givenString).MagicBytesSegment(String aMagicBytes, TransmissionMetrics aTransmissionMetrics) Constructs an according instance for magic bytes of the given length.MagicBytesSegment(TransmissionMetrics aTransmissionMetrics) Constructs an according instance for magic bytes of the given length. -
Method Summary
Modifier and TypeMethodDescriptionintfromTransmission(Sequence aSequence, int aOffset) (Re-)initializes this instance with the the givenSequencedata.intDetermines the overall length of thisTransmission.Provides theSequencerepresentation of thisTransmission.withPayload(byte[] aValue) Methods inherited from class AbstractMagicBytesTransmission
equals, getAlias, getEncoding, getMagicBytes, getMagicBytesLength, getPayload, hashCode, reset, setMagicBytes, setMagicBytes, setMagicBytes, setPayload, toMagicBytesString, toMagicBytesString, toSchema, toSimpleTypeTable, toStringMethods 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.PayloadProperty
letPayloadMethods inherited from interface Segment
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFromMethods inherited from interface Segment.SegmentMixin
receiveFromMethods inherited from interface Transmission
reset, toSimpleTypeTable, transmitTo, transmitToMethods inherited from interface Transmission.TransmissionMixin
transmitTo
-
Constructor Details
-
MagicBytesSegment
public MagicBytesSegment(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.
-
MagicBytesSegment
public MagicBytesSegment(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.
-
MagicBytesSegment
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:
aTransmissionMetrics- TheTransmissionMetricsto be used for configuring this instance.
-
MagicBytesSegment
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:
aMagicBytes- TheStringto be stored by this instance as magic bytes.aTransmissionMetrics- TheTransmissionMetricsto be used for configuring this instance.
-
MagicBytesSegment
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:
aMagicBytes- The bytes to be stored by this instance as magic bytes.aTransmissionMetrics- TheTransmissionMetricsto be used for configuring this instance.
-
MagicBytesSegment
public MagicBytesSegment(int aMagicBytesLength) Constructs an according instance with magic bytes of the given length.- Parameters:
aMagicBytesLength- The length of the magic bytes sequence..
-
MagicBytesSegment
Constructs an according instance with the according magic bytes (retrieved from the givenString).- Parameters:
aMagicBytes- TheStringto be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING) for byte conversion).
-
MagicBytesSegment
Constructs an according instance with the according magic bytes (retrieved from the givenString). -
MagicBytesSegment
public MagicBytesSegment(byte... aMagicBytes) Constructs an according instance with the according magic bytes.- Parameters:
aMagicBytes- The magic bytes to be stored by this instance.
-
MagicBytesSegment
Instantiates the classMagicBytesSegment.- Parameters:
aAlias- the aliasaMagicBytesLength- the magic bytes length- See Also:
-
MagicBytesSegment
Constructs an according instance with 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).
-
MagicBytesSegment
Constructs an according instance with the according magic bytes (retrieved from the givenString). -
MagicBytesSegment
Instantiates the classMagicBytesSegment.- Parameters:
aAlias- the aliasaMagicBytes- the magic bytes- See Also:
-
-
Method Details
-
fromTransmission
(Re-)initializes this instance with the the givenSequencedata.- Specified by:
fromTransmissionin interfaceSegment- Parameters:
aSequence- TheSequencedata from which to (re-)initialize this instance.aOffset- The offset where to start processing the providedSequence.- Returns:
- The index after the last offset into the given
Sequenceprocessed by this method. - Throws:
TransmissionException- thrown in case a givenSequencecannot be processed.
-
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- Overrides:
toSequencein classAbstractMagicBytesTransmission- Returns:
- The according instance's
Sequence.
-
getLength
public int getLength()Determines the overall length of thisTransmission. In case of nestedTransmissioninstances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLengthin interfaceLengthAccessor- Specified by:
getLengthin interfaceTransmission- Returns:
- The (overall) length of the
Transmission(including any sub-segments).
-
withPayload
- Specified by:
withPayloadin interfacePayloadAccessor.PayloadBuilder<byte[], PayloadTransmission<byte[]>>
-