- java.lang.Object
-
- org.refcodes.serial.AbstractPayloadSection<File>
-
- org.refcodes.serial.FileSection
-
- All Implemented Interfaces:
Serializable,org.refcodes.mixin.AliasAccessor,org.refcodes.mixin.LengthAccessor,org.refcodes.mixin.PayloadAccessor<File>,org.refcodes.mixin.PayloadAccessor.PayloadBuilder<File,PayloadTransmission<File>>,org.refcodes.mixin.PayloadAccessor.PayloadMutator<File>,org.refcodes.mixin.PayloadAccessor.PayloadProperty<File>,PayloadSection<File>,PayloadTransmission<File>,Section,Section.SectionMixin,Transmission,Transmission.TransmissionMixin
public class FileSection extends AbstractPayloadSection<File> implements PayloadSection<File>
AFileSectionrepresents aFileon the file system and can be used to receive or to transmit aFile. Using aSupplier, one can use for example aStringSection's value (as ofAbstractPayloadSection.getPayload()) to determine the underlyingFilename dynamically. Whenever the underlyingFileis to be accessed, then theSupplieris called (if provided) to construct the according File dynamically. This way, a file name provided by aStringSectioncan be used for theFileSectionwithin the same transmission.- 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.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.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.SectionMixin
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Constructor Summary
Constructors Constructor Description FileSection(File aFile)Constructs aFileSection.FileSection(File aBasePath, Supplier<String> aFilePathSupplier)Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.FileSection(String aFilePath)Constructs aFileSection.FileSection(String aAlias, File aFile)Constructs aFileSection.FileSection(String aAlias, File aBasePath, Supplier<String> aFilePathSupplier)Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.FileSection(String aAlias, String aFilePath)Constructs aFileSection.FileSection(String aAlias, String aBasePath, Supplier<String> aFilePathSupplier)Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.FileSection(String aBasePath, Supplier<String> aFilePathSupplier)Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.FileSection(Supplier<String> aFilePathSupplier)Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfromTransmission(Sequence aSequence, int aOffset, int aLength)(Re-)initializes this instance with the the givenSequencedata.intgetLength()Determines the overall length of thisTransmission.voidreceiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream)(Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream.FiletoPayloadFile()SchematoSchema()Retrieves theSchemarepresenting theTransmission.SequencetoSequence()Provides theSequencerepresentation of thisTransmission.voidtransmitTo(OutputStream aOutputStream, InputStream aReturnStream)Transmits theSequencerepresenting the implementing type's instance to the givenOutputStream.PayloadTransmission<File>withPayload(File aPayload)-
Methods inherited from class org.refcodes.serial.AbstractPayloadSection
equals, getAlias, getPayload, hashCode, setPayload, toSimpleTypeMap, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.serial.Section
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFrom
-
Methods inherited from interface org.refcodes.serial.Transmission
toSimpleTypeMap, transmitTo, transmitTo
-
-
-
-
Field Detail
-
FILE_PATH
public static final String FILE_PATH
- See Also:
- Constant Field Values
-
FILE_SIZE
public static final String FILE_SIZE
- See Also:
- Constant Field Values
-
FILE_EXISTS
public static final String FILE_EXISTS
- See Also:
- Constant Field Values
-
FILE
public static final String FILE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FileSection
public FileSection(String aAlias, File aFile)
Constructs aFileSection.- Parameters:
aAlias- TheFileSection'S alias.aFile- TheFilerepresenting theFileSection.
-
FileSection
public FileSection(File aFile)
Constructs aFileSection.- Parameters:
aFile- TheFilerepresenting theFileSection.
-
FileSection
public FileSection(String aAlias, String aFilePath)
Constructs aFileSection.- Parameters:
aAlias- TheFileSection'S alias.aFilePath- The file path ofFilerepresenting theFileSection.
-
FileSection
public FileSection(String aFilePath)
Constructs aFileSection.- Parameters:
aFilePath- The file path ofFilerepresenting theFileSection.
-
FileSection
public FileSection(Supplier<String> aFilePathSupplier)
Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.- Parameters:
aFilePathSupplier- TheSupplierof the file path ofFilerepresenting theFileSection. Whenever the underlying file is to be accessed, then theSupplieris called to construct the accordingFile.
-
FileSection
public FileSection(String aAlias, String aBasePath, Supplier<String> aFilePathSupplier)
Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.- Parameters:
aAlias- TheFileSection'S alias.aBasePath- The base path for the path provided by theSupplier.aFilePathSupplier- TheSupplierof the file path ofFilerepresenting theFileSection. Whenever the underlying file is to be accessed, then theSupplieris called to construct the accordingFile.
-
FileSection
public FileSection(String aBasePath, Supplier<String> aFilePathSupplier)
Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.
-
FileSection
public FileSection(String aAlias, File aBasePath, Supplier<String> aFilePathSupplier)
Constructs aFileSection, the underlyingFileis created on demand dynamically using the providedSupplier.- Parameters:
aAlias- TheFileSection'S alias.aBasePath- TheFilerepresenting the base path for the path provided by theSupplier.aFilePathSupplier- TheSupplierof the file path ofFilerepresenting theFileSection. Whenever the underlying file is to be accessed, then theSupplieris called to construct the accordingFile.
-
-
Method Detail
-
toSchema
public Schema toSchema()
Retrieves theSchemarepresenting theTransmission. Retrieving aSchemais useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegmentinstance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment.- Specified by:
toSchemain interfaceTransmission- Returns:
- The
Schemarepresentation of the implementing type for debugging and verification (or documentation) purposes.
-
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, TransmissionException
(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.
-
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 interfaceorg.refcodes.mixin.LengthAccessor- Specified by:
getLengthin interfaceTransmission- Returns:
- The (overall) length of the
Transmission(including any sub-segments).
-
toSequence
public Sequence 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. ATTENTION: Use this method with care as all of theFile's content is loaded into theSequence(and therewith into memory) as a byte array!- Specified by:
toSequencein interfaceTransmission- Returns:
- The according instance's
Sequence.
-
transmitTo
public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
Transmits theSequencerepresenting the implementing type's instance to the givenOutputStream. Implementations providing error correction methods use the provided feedbackInputStreamto do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.- Specified by:
transmitToin interfaceTransmission- Specified by:
transmitToin interfaceTransmission.TransmissionMixin- Parameters:
aOutputStream- TheOutputStreamwhere to write this instance'sSequenceto.aReturnStream- AnInputStreambeing 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 writing data to theOutputStreamcaused problems.
-
withPayload
public PayloadTransmission<File> withPayload(File aPayload)
- Specified by:
withPayloadin interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<File,PayloadTransmission<File>>
-
-