Module org.refcodes.serial
Package org.refcodes.serial
Class MagicBytesSegmentDecorator<DECORATEE extends Segment>
- java.lang.Object
-
- org.refcodes.serial.AbstractMagicBytesTransmission
-
- org.refcodes.serial.AbstractMagicBytesTransmissionDecorator<DECORATEE>
-
- org.refcodes.serial.MagicBytesSegmentDecorator<DECORATEE>
-
- All Implemented Interfaces:
Serializable
,org.refcodes.mixin.AliasAccessor
,org.refcodes.mixin.DecorateeAccessor<DECORATEE>
,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[]>
,DecoratorSegment<DECORATEE>
,MagicBytesAccessor
,MagicBytesAccessor.MagicBytesMutator
,MagicBytesAccessor.MagicBytesProperty
,MagicBytesLengthAccessor
,PayloadTransmission<byte[]>
,Segment
,Segment.SegmentMixin
,Transmission
,Transmission.TransmissionMixin
- Direct Known Subclasses:
AssertMagicBytesSegmentDecorator
public class MagicBytesSegmentDecorator<DECORATEE extends Segment> extends AbstractMagicBytesTransmissionDecorator<DECORATEE> implements Segment.SegmentMixin, DecoratorSegment<DECORATEE>
Magic bytes are usually found (somewhere) at the beginning of a file or a stream. AMagicBytesSegmentDecorator
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.DecorateeAccessor
org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE extends Object,B extends org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE,B>>, org.refcodes.mixin.DecorateeAccessor.DecorateeMutator<DECORATEE extends Object>, org.refcodes.mixin.DecorateeAccessor.DecorateeProperty<DECORATEE extends Object>
-
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.AbstractMagicBytesTransmissionDecorator
_alias, _decoratee
-
Fields inherited from class org.refcodes.serial.AbstractMagicBytesTransmission
_charset, _magicBytes, _magicBytesLength, MAGIC_BYTES, MAGIC_BYTES_TEXT
-
-
Constructor Summary
Constructors Constructor Description MagicBytesSegmentDecorator(DECORATEE aDecoratee, byte... aMagicBytes)
Enriches the providedSegment
with the given magic bytes being prefixed.MagicBytesSegmentDecorator(DECORATEE aDecoratee, int aMagicBytesLength)
Enriches the providedSegment
with magic bytes of the given length to be prefixed.MagicBytesSegmentDecorator(DECORATEE aDecoratee, String aMagicBytes)
MagicBytesSegmentDecorator(DECORATEE aDecoratee, String aMagicBytes, Charset aCharset)
MagicBytesSegmentDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Enriches the provided decoratee with magic bytes of the given length to be prefixed.MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, byte... aMagicBytes)
Enriches the providedSegment
with the given magic bytes being prefixed.MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, int aMagicBytesLength)
Enriches the providedSegment
with magic bytes of the given length to be prefixed.MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, String aMagicBytes)
MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, String aMagicBytes, Charset aCharset)
MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Enriches the provided decoratee with magic bytes of the given length to be prefixed.
-
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.void
receiveFrom(InputStream aInputStream, OutputStream aReturnStream)
Default implementation harnessing theSegment.fromTransmission(Sequence)
method.Schema
toSchema()
Retrieves theSchema
representing theTransmission
.MagicBytesSegmentDecorator<DECORATEE>
withPayload(byte[] aValue)
-
Methods inherited from class org.refcodes.serial.AbstractMagicBytesTransmissionDecorator
equals, getAlias, getDecoratee, getLength, hashCode, setPayload, toSequence, toString
-
Methods inherited from class org.refcodes.serial.AbstractMagicBytesTransmission
getEncoding, getMagicBytes, getMagicBytesLength, getPayload, setMagicBytes, setMagicBytes, setMagicBytes, toMagicBytesString, toMagicBytesString, toSimpleTypeMap
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.serial.MagicBytesAccessor
toMagicBytes, toMagicBytes
-
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.Transmission
getLength, toSequence, toSimpleTypeMap, transmitTo, transmitTo
-
Methods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitTo
-
-
-
-
Constructor Detail
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Enriches the provided decoratee with magic bytes of the given length to be prefixed. The configuration attributes are taken from theTransmissionMetrics
configuration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aDecoratee
- The decoratee which to be prefixed with magic bytes.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Enriches the provided decoratee with magic bytes of the given length to be prefixed. 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.aDecoratee
- The decoratee which to be prefixed with magic bytes.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(DECORATEE aDecoratee, int aMagicBytesLength)
Enriches the providedSegment
with magic bytes of the given length to be prefixed.- Parameters:
aDecoratee
- TheSegment
which is to be prefixed with magic bytes.aMagicBytesLength
- The length of the magic bytes sequence.
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(DECORATEE aDecoratee, String aMagicBytes)
- Parameters:
aDecoratee
- TheSegment
which is to be prefixed with magic bytes.aMagicBytes
- TheString
to be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING
) for byte conversion).
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(DECORATEE aDecoratee, String aMagicBytes, Charset aCharset)
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(DECORATEE aDecoratee, byte... aMagicBytes)
Enriches the providedSegment
with the given magic bytes being prefixed.- Parameters:
aDecoratee
- TheSegment
which is to be prefixed with magic bytes.aMagicBytes
- The magic bytes to be prefixed.
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, int aMagicBytesLength)
Enriches the providedSegment
with magic bytes of the given length to be prefixed.- Parameters:
aAlias
- The alias which identifies the content of this segment.aDecoratee
- TheSegment
which is to be prefixed with magic bytes.aMagicBytesLength
- The length of the magic bytes sequence.
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, String aMagicBytes)
- Parameters:
aAlias
- The alias which identifies the content of this segment.aDecoratee
- TheSegment
which is to be prefixed with magic bytes.aMagicBytes
- TheString
to be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING
) for byte conversion).
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, String aMagicBytes, Charset aCharset)
-
MagicBytesSegmentDecorator
public MagicBytesSegmentDecorator(String aAlias, DECORATEE aDecoratee, byte... aMagicBytes)
Enriches the providedSegment
with the given magic bytes being prefixed.- Parameters:
aAlias
- The alias which identifies the content of this segment.aDecoratee
- TheSegment
which is to be prefixed with magic bytes.aMagicBytes
- The magic bytes to be prefixed.
-
-
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.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, OutputStream aReturnStream) throws IOException, TransmissionException
Default implementation harnessing theSegment.fromTransmission(Sequence)
method. (Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
. Implementations providing error correction methods use the provided feedbackOutputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.- Specified by:
receiveFrom
in interfaceSegment
- Specified by:
receiveFrom
in interfaceSegment.SegmentMixin
- Parameters:
aInputStream
- TheInputStream
from which to read the instance's (re-)initializationSequence
from.aReturnStream
- AnOutputStream
being the return channel to handle "stop-and-wait ARQ" or the like in case of a bidirectional connection. Can be null in case we have a unidirectional connection.- Throws:
IOException
- thrown in case reading data from theInputStream
caused problems.TransmissionException
- thrown in case a given transmission cannot be processed.
-
withPayload
public MagicBytesSegmentDecorator<DECORATEE> withPayload(byte[] aValue)
- Specified by:
withPayload
in interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<byte[],PayloadTransmission<byte[]>>
-
toSchema
public Schema toSchema()
Retrieves theSchema
representing theTransmission
. Retrieving aSchema
is useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegment
instance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment
.- Specified by:
toSchema
in interfaceTransmission
- Overrides:
toSchema
in classAbstractMagicBytesTransmissionDecorator<DECORATEE extends Segment>
- Returns:
- The
Schema
representation of the implementing type for debugging and verification (or documentation) purposes.
-
-