I log sensor data with my Android phone and serialize it using the FST library (Ruediger Moeller). While it works well, saving data at the end of long sessions takes time. I’d prefer to append data every minute or something to reduce end-of-session save time and ensure all data isn’t lost if the app crashes.
I know it’s possible to append data using ObjectOutputStream
by overriding writeStreamHeader()
to avoid writing the header. However, FSTObjectOutput
doesn’t have writeStreamHeader()
. Does anyone know how to achieve appending with the FST library?
The current java code looks like this without appending:
public void writeFile(String pathFileName) {
try {
RandomAccessFile raf = new RandomAccessFile(pathFileName, "rw");
FileOutputStream fos = new FileOutputStream(raf.getFD());
FSTObjectOutput os = new FSTObjectOutput(fos);
os.writeObject(mySensorDataObject, SensorDataObject.getClass());
os.flush();
os.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
public void readFile(String pathFileName) {
try {
RandomAccessFile raf = new RandomAccessFile(pathFileName, "r");
FileInputStream fis = new FileInputStream(raf.getFD());
BufferedInputStream bos = new BufferedInputStream(fis);
FSTObjectInput is = new FSTObjectInput(bos);
mySensorDataObject.addAll((SensorDataObject) is.readObject(SensorDataObject.getClass()));
is.close();
}
catch(Exception e) {
e.printStackTrace();
}
}