1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-30 10:34:03 +02:00

Fix some file closing issues

This commit is contained in:
cpfeiffer 2018-09-15 23:54:51 +02:00
parent 8aad6cd620
commit ce2f984e9f
2 changed files with 6 additions and 8 deletions

View File

@ -60,8 +60,8 @@ public class GPXExporter implements ActivityTrackExporter {
public void performExport(ActivityTrack track, File targetFile) throws IOException, GPXTrackEmptyException {
String encoding = StandardCharsets.UTF_8.name();
XmlSerializer ser = Xml.newSerializer();
try {
ser.setOutput(new FileOutputStream(targetFile), encoding);
try (FileOutputStream outputStream = new FileOutputStream(targetFile)) {
ser.setOutput(outputStream, encoding);
ser.startDocument(encoding, Boolean.TRUE);
ser.setPrefix("xsi", NS_XSI_URI);
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_URI);
@ -77,7 +77,6 @@ public class GPXExporter implements ActivityTrackExporter {
ser.endTag(NS_DEFAULT, "gpx");
ser.endDocument();
} finally {
ser.flush();
}
}

View File

@ -50,11 +50,12 @@ public class ImportExportSharedPreferences {
public static void exportToFile(SharedPreferences sharedPreferences, File outFile,
Set<String> doNotExport) throws IOException {
export(sharedPreferences, new FileWriter(outFile), doNotExport);
try (FileWriter outputWriter = new FileWriter(outFile)) {
export(sharedPreferences, outputWriter, doNotExport);
}
}
public static void export(SharedPreferences sharedPreferences, Writer writer,
private static void export(SharedPreferences sharedPreferences, Writer writer,
Set<String> doNotExport) throws IOException {
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(writer);
@ -75,11 +76,9 @@ public class ImportExportSharedPreferences {
serializer.attribute("", NAME, key);
serializer.text(value);
serializer.endTag("", valueType);
}
serializer.endTag("", PREFERENCES);
serializer.endDocument();
writer.close();
}
public static boolean importFromFile(SharedPreferences sharedPreferences, File inFile)