- java.lang.Object
-
- org.refcodes.serial.AbstractMagicBytesTransmission
-
- org.refcodes.serial.MagicBytesSegment
-
- 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[]>
,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. AMagicBytesSegment
decorates aSegment
decoratee and prefixes thisSegment
instance with given 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.Segment
Segment.SegmentMixin
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Field Summary
-
Fields inherited from class org.refcodes.serial.AbstractMagicBytesTransmission
_alias, _charset, _magicBytes, _magicBytesLength, MAGIC_BYTES, MAGIC_BYTES_TEXT
-
-
Constructor Summary
Constructors Constructor Description MagicBytesSegment(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)
Constructs an according instance with the according magic bytes.MagicBytesSegment(String aAlias, byte[] aMagicBytes, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance for magic bytes of the given length.MagicBytesSegment(String aAlias, int aMagicBytesLength)
Constructs an according instance with magic bytes of the given length.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
fromTransmission(Sequence aSequence, int aOffset)
(Re-)initializes this instance with the the givenSequence
data.int
getLength()
Determines the overall length of thisTransmission
.Sequence
toTransmission()
Provides theSequence
representation of thisTransmission
.MagicBytesSegment
withPayload(byte[] aValue)
-
Methods inherited from class org.refcodes.serial.AbstractMagicBytesTransmission
equals, getAlias, getEncoding, getMagicBytes, getMagicBytesLength, getPayload, hashCode, setMagicBytes, setMagicBytes, setMagicBytes, setPayload, toMagicBytesString, toMagicBytesString, toSchema, toSimpleTypeMap, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
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.Segment
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFrom
-
Methods inherited from interface org.refcodes.serial.Segment.SegmentMixin
receiveFrom
-
Methods inherited from interface org.refcodes.serial.Transmission
toSchema, toSimpleTypeMap, transmitTo, transmitTo
-
Methods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitTo
-
-
-
-
Constructor Detail
-
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 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.
-
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 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.
-
MagicBytesSegment
public MagicBytesSegment(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:
aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
MagicBytesSegment
public MagicBytesSegment(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:
aMagicBytes
- TheString
to be stored by this instance as magic bytes.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
MagicBytesSegment
public MagicBytesSegment(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:
aMagicBytes
- The bytes to be stored by this instance as magic bytes.aTransmissionMetrics
- TheTransmissionMetrics
to 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
public MagicBytesSegment(String aMagicBytes)
Constructs an according instance with the according magic bytes (retrieved from the givenString
).- Parameters:
aMagicBytes
- TheString
to be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING
) for byte conversion).
-
MagicBytesSegment
public MagicBytesSegment(String aMagicBytes, Charset aCharset)
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
public MagicBytesSegment(String aAlias, int aMagicBytesLength)
Constructs an according instance with 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..
-
MagicBytesSegment
public MagicBytesSegment(String aAlias, String aMagicBytes)
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
- TheString
to be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING
) for byte conversion).
-
MagicBytesSegment
public MagicBytesSegment(String aAlias, String aMagicBytes, Charset aCharset)
Constructs an according instance with the according magic bytes (retrieved from the givenString
).
-
MagicBytesSegment
public MagicBytesSegment(String aAlias, byte... aMagicBytes)
Constructs an according instance 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
-
fromTransmission
public int fromTransmission(Sequence aSequence, int aOffset) throws TransmissionException
(Re-)initializes this instance with the the givenSequence
data.- Specified by:
fromTransmission
in interfaceSegment
- Parameters:
aSequence
- TheSequence
data 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
Sequence
processed by this method. - Throws:
TransmissionException
- thrown in case a givenSequence
cannot be processed.
-
toTransmission
public Sequence toTransmission()
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well.- Specified by:
toTransmission
in interfaceTransmission
- Overrides:
toTransmission
in classAbstractMagicBytesTransmission
- Returns:
- The according instance's
Sequence
.
-
getLength
public int getLength()
Determines the overall length of thisTransmission
. In case of nestedTransmission
instances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLength
in interfaceorg.refcodes.mixin.LengthAccessor
- Specified by:
getLength
in interfaceTransmission
- Returns:
- The (overall) length of the
Transmission
(including any sub-segments).
-
withPayload
public MagicBytesSegment withPayload(byte[] aValue)
- Specified by:
withPayload
in interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<byte[],PayloadTransmission<byte[]>>
-
-