name = name.substring(prefixLength).replace('=', EQUALS_SIGN_REPL);
valuesToSave.add(name + (editable ? "=" : "==") + valStr);
}
// Write the saved values
RobustFileWriter rfw;
BufferedWriter out;
try {
String encoding = getDatasetEncoding();
rfw = new RobustFileWriter(datafile.file, encoding);
} catch (IOException e) {
logger.log(Level.SEVERE, "Encountered exception while opening "
+ datafile.file.getPath() + "; save aborted", e);
return;
}
try {
out = new BufferedWriter(rfw);
// if the data file has an include statement, write it to the file
if (datafile.inheritsFrom != null) {
out.write(includeTag + datafile.inheritsFrom);
out.newLine();
}
// If the data file has a prefix, write it as a comment to the file
if (datafile.prefix != null && datafile.prefix.length() > 0) {
out.write("= Data for " + datafile.prefix);
out.newLine();
}
for (Iterator i = valuesToSave.iterator(); i.hasNext();) {
out.write((String) i.next());
out.newLine();
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Encountered exception while writing to "
+ datafile.file.getPath() + "; save aborted", e);
try { rfw.abort(); } catch (Exception ex) {}
return;
}
try {
// Close output file
out.flush();
out.close();
saveSuccessful = true;
System.err.println("Saved " + datafile.file.getPath());
} catch (IOException e) {
logger.log(Level.SEVERE, "Encountered exception while closing "
+ datafile.file.getPath() + "; save aborted", e);
try { rfw.abort(); } catch (Exception ex) {}
}
} finally {
// if we couldn't successfully save the datafile, mark it as dirty.
if (!saveSuccessful)