mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
Fix some file closing issues
This commit is contained in:
parent
8aad6cd620
commit
ce2f984e9f
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user