Class 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>, org.refcodes.mixin.Schemable, PayloadSection<File>, PayloadTransmission<File>, Section, Section.SectionMixin, Transmission, Transmission.TransmissionMixin

public class FileSection extends AbstractPayloadSection<File>
A FileSection represents a File on the file system and can be used to receive or to transmit a File. Using a Supplier, one can use for example a StringSection's value (as of AbstractPayloadSection.getPayload()) to determine the underlying File name dynamically. Whenever the underlying File is to be accessed, then the Supplier is called (if provided) to construct the according File dynamically. This way, a file name provided by a StringSection can be used for the FileSection within the same transmission.
See Also:
  • Field Details

  • Constructor Details

    • FileSection

      public FileSection(String aAlias, File aFile)
      Constructs a FileSection.
      Parameters:
      aAlias - The FileSection'S alias.
      aFile - The File representing the FileSection.
    • FileSection

      public FileSection(File aFile)
      Constructs a FileSection.
      Parameters:
      aFile - The File representing the FileSection.
    • FileSection

      public FileSection(String aAlias, String aFilePath)
      Constructs a FileSection.
      Parameters:
      aAlias - The FileSection'S alias.
      aFilePath - The file path of File representing the FileSection.
    • FileSection

      public FileSection(String aFilePath)
      Constructs a FileSection.
      Parameters:
      aFilePath - The file path of File representing the FileSection.
    • FileSection

      public FileSection(Supplier<String> aFilePathSupplier)
      Constructs a FileSection, the underlying File is created on demand dynamically using the provided Supplier.
      Parameters:
      aFilePathSupplier - The Supplier of the file path of File representing the FileSection. Whenever the underlying file is to be accessed, then the Supplier is called to construct the according File.
    • FileSection

      public FileSection(String aAlias, String aBasePath, Supplier<String> aFilePathSupplier)
      Constructs a FileSection, the underlying File is created on demand dynamically using the provided Supplier.
      Parameters:
      aAlias - The FileSection'S alias.
      aBasePath - The base path for the path provided by the Supplier.
      aFilePathSupplier - The Supplier of the file path of File representing the FileSection. Whenever the underlying file is to be accessed, then the Supplier is called to construct the according File.
    • FileSection

      public FileSection(String aBasePath, Supplier<String> aFilePathSupplier)
      Constructs a FileSection, the underlying File is created on demand dynamically using the provided Supplier.
      Parameters:
      aBasePath - The base path for the path provided by the Supplier.
      aFilePathSupplier - The Supplier of the file path of File representing the FileSection. Whenever the underlying file is to be accessed, then the Supplier is called to construct the according File.
    • FileSection

      public FileSection(String aAlias, File aBasePath, Supplier<String> aFilePathSupplier)
      Constructs a FileSection, the underlying File is created on demand dynamically using the provided Supplier.
      Parameters:
      aAlias - The FileSection'S alias.
      aBasePath - The File representing the base path for the path provided by the Supplier.
      aFilePathSupplier - The Supplier of the file path of File representing the FileSection. Whenever the underlying file is to be accessed, then the Supplier is called to construct the according File.
    • FileSection

      public FileSection(File aBasePath, Supplier<String> aFilePathSupplier)
      Constructs a FileSection, the underlying File is created on demand dynamically using the provided Supplier.
      Parameters:
      aBasePath - The File representing the base path for the path provided by the Supplier.
      aFilePathSupplier - The Supplier of the file path of File representing the FileSection. Whenever the underlying file is to be accessed, then the Supplier is called to construct the according File.
  • Method Details

    • toSchema

      public SerialSchema toSchema()
    • fromTransmission

      public void fromTransmission(Sequence aSequence, int aOffset, int aLength) throws TransmissionException
      (Re-)initializes this instance with the the given Sequence data.
      Parameters:
      aSequence - The Sequence data from which to (re-)initialize this instance.
      aOffset - The offset where to start processing the provided Sequence.
      aLength - The length of data assigned by the Sequence.
      Throws:
      TransmissionException - thrown in case a given Sequence cannot be processed.
    • receiveFrom

      public void receiveFrom(InputStream aInputStream, int aLength, OutputStream aReturnStream) throws IOException
      (Re-)initializes this instance by receiving the according Sequence from the given InputStream. Implementations providing error correction methods use the provided feedback OutputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.
      Parameters:
      aInputStream - The InputStream from which to read the instance's (re-)initialization Sequence from.
      aLength - The length of data assigned by the byte array.
      aReturnStream - An OutputStream 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 the InputStream caused problems.
      TransmissionException - thrown in case a given InputStream bytes cannot be processed.
    • getLength

      public int getLength()
      Determines the overall length of this Transmission. In case of nested Transmission instances, all length values from all sub-segments are accumulated to the result as well.
      Returns:
      The (overall) length of the Transmission (including any sub-segments).
    • toSequence

      public Sequence toSequence()
      Provides the Sequence representation of this Transmission. In case of nested Transmission instances, all Sequence representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nested Transmission instances) may be backed by the returned Sequence. ATTENTION: Use this method with care as all of the File's content is loaded into the Sequence (and therewith into memory) as a byte array!
      Returns:
      The according instance's Sequence.
    • transmitTo

      public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
      Transmits the Sequence representing the implementing type's instance to the given OutputStream. Implementations providing error correction methods use the provided feedback InputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.
      Parameters:
      aOutputStream - The OutputStream where to write this instance's Sequence to.
      aReturnStream - An InputStream 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 the OutputStream caused problems.
    • withPayload

      public PayloadTransmission<File> withPayload(File aPayload)
    • toPayloadFile

      public File toPayloadFile()
      Determines whether we have a "dynamic" File as of a Supplier being or a "static" File (or a file path).
      Returns:
      The according File.