Module org.refcodes.serial
Package org.refcodes.serial
Class MagicBytesSectionDecorator<DECORATEE extends Section>
java.lang.Object
org.refcodes.serial.AbstractMagicBytesTransmission
org.refcodes.serial.AbstractMagicBytesTransmissionDecorator<DECORATEE>
org.refcodes.serial.MagicBytesSectionDecorator<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[]>,org.refcodes.mixin.Resetable,org.refcodes.schema.Schemable,DecoratorSection<DECORATEE>,MagicBytesAccessor,MagicBytesAccessor.MagicBytesMutator,MagicBytesAccessor.MagicBytesProperty,MagicBytesLengthAccessor,PayloadTransmission<byte[]>,Section,Section.SectionMixin,Transmission,Transmission.TransmissionMixin
- Direct Known Subclasses:
AssertMagicBytesSectionDecorator
public class MagicBytesSectionDecorator<DECORATEE extends Section>
extends AbstractMagicBytesTransmissionDecorator<DECORATEE>
implements Section.SectionMixin, DecoratorSection<DECORATEE>
Magic bytes are usually found (somewhere) at the beginning of a file or a
stream. A
MagicBytesSectionDecorator decorates a Section
decoratee and prefixes this Section instance with given magic bytes.- See Also:
-
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.AliasPropertyNested 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.LengthPropertyNested 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.MagicBytesPropertyNested classes/interfaces inherited from interface org.refcodes.serial.MagicBytesAccessor
MagicBytesAccessor.MagicBytesBuilder<B extends MagicBytesAccessor.MagicBytesBuilder<B>>, MagicBytesAccessor.MagicBytesMutator, MagicBytesAccessor.MagicBytesPropertyNested classes/interfaces inherited from interface org.refcodes.serial.MagicBytesLengthAccessor
MagicBytesLengthAccessor.MagicBytesLengthBuilder<B extends MagicBytesLengthAccessor.MagicBytesLengthBuilder<B>>, MagicBytesLengthAccessor.MagicBytesLengthMutator, MagicBytesLengthAccessor.MagicBytesLengthPropertyNested 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.Section
Section.SectionMixinNested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin -
Field Summary
Fields inherited from class org.refcodes.serial.AbstractMagicBytesTransmissionDecorator
_alias, _decorateeFields inherited from class org.refcodes.serial.AbstractMagicBytesTransmission
_charset, _magicBytes, _magicBytesLength, MAGIC_BYTES, MAGIC_BYTES_TEXT -
Constructor Summary
ConstructorsConstructorDescriptionMagicBytesSectionDecorator(DECORATEE aDecoratee, byte[] aMagicBytes) Enriches the providedSectionwith the given magic bytes being prefixed.MagicBytesSectionDecorator(DECORATEE aDecoratee, int aMagicBytesLength) Enriches the providedSectionwith magic bytes of the given length to be prefixed.MagicBytesSectionDecorator(DECORATEE aDecoratee, String aMagicBytes) MagicBytesSectionDecorator(DECORATEE aDecoratee, String aMagicBytes, Charset aCharset) MagicBytesSectionDecorator(String aAlias, DECORATEE aDecoratee, byte[] aMagicBytes) Enriches the providedSectionwith the given magic bytes being prefixed.MagicBytesSectionDecorator(String aAlias, DECORATEE aDecoratee, int aMagicBytesLength) Enriches the providedSectionwith magic bytes of the given length to be prefixed.MagicBytesSectionDecorator(String aAlias, DECORATEE aDecoratee, String aMagicBytes) MagicBytesSectionDecorator(String aAlias, DECORATEE aDecoratee, String aMagicBytes, Charset aCharset) MagicBytesSectionDecorator(String aAlias, DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics) Enriches the provided decoratee with magic bytes of the given length to be prefixed. -
Method Summary
Modifier and TypeMethodDescriptionvoidfromTransmission(Sequence aSequence, int aOffset, int aLength) (Re-)initializes this instance with the the givenSequencedata.voidreceiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) Default implementation harnessing theSection.fromTransmission(Sequence, int)method.toSchema()withPayload(byte[] aValue) Methods inherited from class org.refcodes.serial.AbstractMagicBytesTransmissionDecorator
equals, getAlias, getDecoratee, getLength, hashCode, reset, setPayload, toSequence, toStringMethods inherited from class org.refcodes.serial.AbstractMagicBytesTransmission
getEncoding, getMagicBytes, getMagicBytesLength, getPayload, setMagicBytes, setMagicBytes, setMagicBytes, toMagicBytesString, toMagicBytesString, toSimpleTypeMapMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.refcodes.mixin.DecorateeAccessor
getDecorateeMethods inherited from interface org.refcodes.serial.MagicBytesAccessor
toMagicBytes, toMagicBytesMethods inherited from interface org.refcodes.mixin.MagicBytesAccessor.MagicBytesProperty
letMagicBytes, letMagicBytesMethods inherited from interface org.refcodes.serial.MagicBytesAccessor.MagicBytesProperty
letMagicBytesMethods inherited from interface org.refcodes.mixin.PayloadAccessor
getPayloadOrMethods inherited from interface org.refcodes.mixin.PayloadAccessor.PayloadProperty
letPayloadMethods inherited from interface org.refcodes.serial.Section
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFromMethods inherited from interface org.refcodes.serial.Transmission
getLength, reset, toSequence, toSimpleTypeMap, transmitTo, transmitToMethods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitTo
-
Constructor Details
-
MagicBytesSectionDecorator
public MagicBytesSectionDecorator(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 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.aDecoratee- The decoratee which to be prefixed with magic bytes.aTransmissionMetrics- TheTransmissionMetricsto be used for configuring this instance.
-
MagicBytesSectionDecorator
Enriches the providedSectionwith magic bytes of the given length to be prefixed.- Parameters:
aDecoratee- TheSectionwhich is to be prefixed with magic bytes.aMagicBytesLength- The length of the magic bytes sequence.
-
MagicBytesSectionDecorator
- Parameters:
aDecoratee- TheSectionwhich is to be prefixed with magic bytes.aMagicBytes- TheStringto be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING) for byte conversion).
-
MagicBytesSectionDecorator
-
MagicBytesSectionDecorator
Enriches the providedSectionwith the given magic bytes being prefixed.- Parameters:
aDecoratee- TheSectionwhich is to be prefixed with magic bytes.aMagicBytes- The magic bytes to be prefixed.
-
MagicBytesSectionDecorator
Enriches the providedSectionwith magic bytes of the given length to be prefixed.- Parameters:
aAlias- The alias which identifies the content of this segment.aDecoratee- TheSectionwhich is to be prefixed with magic bytes.aMagicBytesLength- The length of the magic bytes sequence.
-
MagicBytesSectionDecorator
- Parameters:
aAlias- The alias which identifies the content of this segment.aDecoratee- TheSectionwhich is to be prefixed with magic bytes.aMagicBytes- TheStringto be stored by this instance as magic bytes (uses theTransmissionMetrics.DEFAULT_ENCODING) for byte conversion).
-
MagicBytesSectionDecorator
-
MagicBytesSectionDecorator
Enriches the providedSectionwith the given magic bytes being prefixed.- Parameters:
aAlias- The alias which identifies the content of this segment.aDecoratee- TheSectionwhich is to be prefixed with magic bytes.aMagicBytes- The magic bytes to be prefixed.
-
-
Method Details
-
fromTransmission
public void fromTransmission(Sequence aSequence, int aOffset, int aLength) throws TransmissionException (Re-)initializes this instance with the the givenSequencedata.- Specified by:
fromTransmissionin interfaceSection- Parameters:
aSequence- TheSequencedata from which to (re-)initialize this instance.aOffset- The offset where to start processing the providedSequence.aLength- The length of data assigned by theSequence.- Throws:
TransmissionException- thrown in case a givenSequencecannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) throws IOException Default implementation harnessing theSection.fromTransmission(Sequence, int)method. (Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream. Implementations providing error correction methods use the provided feedbackOutputStreamto do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.- Specified by:
receiveFromin interfaceSection- Specified by:
receiveFromin interfaceSection.SectionMixin- Parameters:
aInputStream- TheInputStreamfrom which to read the instance's (re-)initializationSequencefrom.aLength- The length of data assigned by the byte array.aReturnStream- AnOutputStreambeing 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 theInputStreamcaused problems.TransmissionException- thrown in case a givenInputStreambytes cannot be processed.
-
withPayload
- Specified by:
withPayloadin interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<byte[],PayloadTransmission<byte[]>>
-
toSchema
- Specified by:
toSchemain interfaceorg.refcodes.schema.Schemable- Specified by:
toSchemain interfaceTransmission- Overrides:
toSchemain classAbstractMagicBytesTransmissionDecorator<DECORATEE extends Section>
-