mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-12 04:59:27 +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 {
|
public void performExport(ActivityTrack track, File targetFile) throws IOException, GPXTrackEmptyException {
|
||||||
String encoding = StandardCharsets.UTF_8.name();
|
String encoding = StandardCharsets.UTF_8.name();
|
||||||
XmlSerializer ser = Xml.newSerializer();
|
XmlSerializer ser = Xml.newSerializer();
|
||||||
try {
|
try (FileOutputStream outputStream = new FileOutputStream(targetFile)) {
|
||||||
ser.setOutput(new FileOutputStream(targetFile), encoding);
|
ser.setOutput(outputStream, encoding);
|
||||||
ser.startDocument(encoding, Boolean.TRUE);
|
ser.startDocument(encoding, Boolean.TRUE);
|
||||||
ser.setPrefix("xsi", NS_XSI_URI);
|
ser.setPrefix("xsi", NS_XSI_URI);
|
||||||
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_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.endTag(NS_DEFAULT, "gpx");
|
||||||
ser.endDocument();
|
ser.endDocument();
|
||||||
} finally {
|
|
||||||
ser.flush();
|
ser.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,12 @@ public class ImportExportSharedPreferences {
|
|||||||
|
|
||||||
public static void exportToFile(SharedPreferences sharedPreferences, File outFile,
|
public static void exportToFile(SharedPreferences sharedPreferences, File outFile,
|
||||||
Set<String> doNotExport) throws IOException {
|
Set<String> doNotExport) throws IOException {
|
||||||
export(sharedPreferences, new FileWriter(outFile), doNotExport);
|
try (FileWriter outputWriter = new FileWriter(outFile)) {
|
||||||
|
export(sharedPreferences, outputWriter, doNotExport);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void export(SharedPreferences sharedPreferences, Writer writer,
|
||||||
public static void export(SharedPreferences sharedPreferences, Writer writer,
|
|
||||||
Set<String> doNotExport) throws IOException {
|
Set<String> doNotExport) throws IOException {
|
||||||
XmlSerializer serializer = Xml.newSerializer();
|
XmlSerializer serializer = Xml.newSerializer();
|
||||||
serializer.setOutput(writer);
|
serializer.setOutput(writer);
|
||||||
@ -75,11 +76,9 @@ public class ImportExportSharedPreferences {
|
|||||||
serializer.attribute("", NAME, key);
|
serializer.attribute("", NAME, key);
|
||||||
serializer.text(value);
|
serializer.text(value);
|
||||||
serializer.endTag("", valueType);
|
serializer.endTag("", valueType);
|
||||||
|
|
||||||
}
|
}
|
||||||
serializer.endTag("", PREFERENCES);
|
serializer.endTag("", PREFERENCES);
|
||||||
serializer.endDocument();
|
serializer.endDocument();
|
||||||
writer.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean importFromFile(SharedPreferences sharedPreferences, File inFile)
|
public static boolean importFromFile(SharedPreferences sharedPreferences, File inFile)
|
||||||
|
Loading…
Reference in New Issue
Block a user