Class OutgoingFileSource

java.lang.Object
org.yamcs.cfdp.OutgoingFileSource
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
OutgoingFileSource.DiskSource

public abstract class OutgoingFileSource extends Object implements AutoCloseable
The data of a file being sent (uplinked) by CFDP.

The data is read in pieces with positional reads, so the file does not have to be kept in memory. Two implementations exist: a file on disk (normally a copy of the bucket object in the transfer directory) and an in memory array (used for tests or when no transfer directory is available).

The reads are performed from the CFDP executor thread; they are not synchronized.

  • Constructor Details

    • OutgoingFileSource

      public OutgoingFileSource()
  • Method Details

    • size

      public abstract long size()
      Returns:
      the size of the file
    • read

      public abstract void read(long pos, byte[] dst, int off, int len) throws IOException
      Reads exactly len bytes starting at position pos in the file into dst[off..off+len).
      Throws:
      IOException - if the data cannot be read or the file is shorter than pos+len
    • checksum

      public long checksum(long length) throws IOException
      Computes the CFDP modular checksum of the first length bytes of the file by streaming it.
      Throws:
      IOException
    • close

      public abstract void close()
      Specified by:
      close in interface AutoCloseable
    • ofBytes

      public static OutgoingFileSource ofBytes(byte[] data)
    • createFile

      public static OutgoingFileSource.DiskSource createFile(Path path, byte[] data) throws IOException
      Writes the data into a new file at the given path (truncating it if it exists), syncs it to disk and returns a source reading from that file.
      Throws:
      IOException
    • openFile

      public static OutgoingFileSource.DiskSource openFile(Path path) throws IOException
      Opens an existing file
      Throws:
      IOException