Skip to content

FileDataManager

A data manager that writes Measurements as JSON to files on the phone.

Used when the protocol's data endpoint is a FileDataEndPoint. Each file holds a JSON array of measurements. When a file grows beyond FileDataEndPoint.bufferSize bytes, it is closed, optionally zipped, and a new file is started.

Key points:

The path and filename format is

~/carp/deployments/<study_deployment_id>/data/carp-data-yyyy-mm-dd-hh-mm-ss-ms.json.zip

where ~ is the folder where an application can place files that are private to the application (see Settings.getDataBasePath).

On iOS, this is the NSDocumentsDirectory and the files can be accessed via the MacOS Finder.

On Android, Flutter files are stored in the AppData directory, which is located in the data/data/<package_name>/app_flutter folder. Files can be accessed via AndroidStudio.

Inheritance

Constructors

FileDataManager

FileDataManager()

Properties

file

Future<File> get file

The current file being written to.

Created on first access, which also emits a FileDataManagerEventTypes.fileCreated event.

fileDataEndPoint

FileDataEndPoint get fileDataEndPoint

The dataEndPoint cast to a FileDataEndPoint. Only valid after configure has been called.

filename

Future<String> get filename

Full path and filename of the current file, on the format

~/carp/deployments/<study_deployment_id>/data/carp-data-yyyy-mm-dd-hh-mm-ss-ms.json

where the date is the creation time in UTC (zulu time). A new name is generated each time a file is flushed.

path

Future<String> get path

The full path where data files are stored on the device.

sink

Future<IOSink> get sink

The IOSink used to append to the current file.

Opened on first access, which also writes the opening [ of the JSON array.

type

String get type
override

The type of this data manager as enumerated in DataEndPointTypes.

Methods

close

Future<void> close()
override

Flushes any buffered data and closes this data manager.

After calling close the data manager can no longer be used.

configure

Future<void> configure({
  1. required DataEndPoint dataEndPoint,
  2. required SmartphoneDeployment deployment,
  3. required Stream<Measurement> measurements,
})
override

Configures the data manager with the study deployment, the dataEndPoint, and the stream of measurements to handle.

Call this before any data is handled.

flush

Future<void> flush(
  1. File flushFile,
  2. IOSink flushSink
)

Closes flushFile and its flushSink, and zips the file if FileDataEndPoint.zip is true.

Resets the current file, so the next write starts a new file. Emits a FileDataManagerEventTypes.fileClosed event with the final path (ending in .zip if zipped). Calls for a sink that is already being flushed are ignored.

onDone

Future<void> onDone()
override

When the data stream closes, the onDone handler is called. Default implementation is a no-op function. If another behavior is wanted, implementations of this abstract data manager should handle closing of the data stream.

onMeasurement

Future<void> onMeasurement(
  1. Measurement measurement
)
override

On each measurement collected, the onMeasurement handler is called.

Implementations of this interface should handle how to save or upload the measurement.

write

Future<void> write(
  1. Measurement measurement
)

Writes a JSON encoded measurement to the current file.

If the sink is not ready, the write is retried after 2 seconds. Calls flush when the file size exceeds FileDataEndPoint.bufferSize.