- 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>
AFileSection
represents aFile
on 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 underlyingFile
name dynamically. Whenever the underlyingFile
is to be accessed, then theSupplier
is called (if provided) to construct the according File dynamically. This way, a file name provided by aStringSection
can be used for theFileSection
within 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 underlyingFile
is 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 underlyingFile
is 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 underlyingFile
is created on demand dynamically using the providedSupplier
.FileSection(String aBasePath, Supplier<String> aFilePathSupplier)
Constructs aFileSection
, the underlyingFile
is created on demand dynamically using the providedSupplier
.FileSection(Supplier<String> aFilePathSupplier)
Constructs aFileSection
, the underlyingFile
is created on demand dynamically using the providedSupplier
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fromTransmission(Sequence aSequence, int aOffset, int aLength)
(Re-)initializes this instance with the the givenSequence
data.int
getLength()
Determines the overall length of thisTransmission
.void
receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream)
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
.File
toPayloadFile()
Schema
toSchema()
Retrieves theSchema
representing theTransmission
.Sequence
toSequence()
Provides theSequence
representation of thisTransmission
.void
transmitTo(OutputStream aOutputStream, InputStream aReturnStream)
Transmits theSequence
representing 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
- TheFile
representing theFileSection
.
-
FileSection
public FileSection(File aFile)
Constructs aFileSection
.- Parameters:
aFile
- TheFile
representing theFileSection
.
-
FileSection
public FileSection(String aAlias, String aFilePath)
Constructs aFileSection
.- Parameters:
aAlias
- TheFileSection
'S alias.aFilePath
- The file path ofFile
representing theFileSection
.
-
FileSection
public FileSection(String aFilePath)
Constructs aFileSection
.- Parameters:
aFilePath
- The file path ofFile
representing theFileSection
.
-
FileSection
public FileSection(Supplier<String> aFilePathSupplier)
Constructs aFileSection
, the underlyingFile
is created on demand dynamically using the providedSupplier
.- Parameters:
aFilePathSupplier
- TheSupplier
of the file path ofFile
representing theFileSection
. Whenever the underlying file is to be accessed, then theSupplier
is called to construct the accordingFile
.
-
FileSection
public FileSection(String aAlias, String aBasePath, Supplier<String> aFilePathSupplier)
Constructs aFileSection
, the underlyingFile
is created on demand dynamically using the providedSupplier
.- Parameters:
aAlias
- TheFileSection
'S alias.aBasePath
- The base path for the path provided by theSupplier
.aFilePathSupplier
- TheSupplier
of the file path ofFile
representing theFileSection
. Whenever the underlying file is to be accessed, then theSupplier
is called to construct the accordingFile
.
-
FileSection
public FileSection(String aBasePath, Supplier<String> aFilePathSupplier)
Constructs aFileSection
, the underlyingFile
is created on demand dynamically using the providedSupplier
.
-
FileSection
public FileSection(String aAlias, File aBasePath, Supplier<String> aFilePathSupplier)
Constructs aFileSection
, the underlyingFile
is created on demand dynamically using the providedSupplier
.- Parameters:
aAlias
- TheFileSection
'S alias.aBasePath
- TheFile
representing the base path for the path provided by theSupplier
.aFilePathSupplier
- TheSupplier
of the file path ofFile
representing theFileSection
. Whenever the underlying file is to be accessed, then theSupplier
is called to construct the accordingFile
.
-
-
Method Detail
-
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
- Returns:
- The
Schema
representation 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 givenSequence
data.- Specified by:
fromTransmission
in interfaceSection
- Parameters:
aSequence
- TheSequence
data 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 givenSequence
cannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) throws IOException, TransmissionException
(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 interfaceSection
- Specified by:
receiveFrom
in interfaceSection.SectionMixin
- Parameters:
aInputStream
- TheInputStream
from which to read the instance's (re-)initializationSequence
from.aLength
- The length of data assigned by the byte array.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 givenInputStream
bytes cannot be processed.
-
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).
-
toSequence
public Sequence toSequence()
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmission
instances) 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:
toSequence
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
transmitTo
public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
Transmits theSequence
representing the implementing type's instance to the givenOutputStream
. Implementations providing error correction methods use the provided feedbackInputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.- Specified by:
transmitTo
in interfaceTransmission
- Specified by:
transmitTo
in interfaceTransmission.TransmissionMixin
- Parameters:
aOutputStream
- TheOutputStream
where to write this instance'sSequence
to.aReturnStream
- AnInputStream
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 writing data to theOutputStream
caused problems.
-
withPayload
public PayloadTransmission<File> withPayload(File aPayload)
- Specified by:
withPayload
in interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<File,PayloadTransmission<File>>
-
-