1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Use try-with-resources to ensure stream is closed on exception

This commit is contained in:
cpfeiffer 2017-04-12 20:48:28 +02:00
parent 6ed40a21c6
commit 589945f234

View File

@ -176,14 +176,11 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
static synchronized void rewriteAppOrderFile(String filename, List<UUID> uuids) {
try {
FileWriter fileWriter = new FileWriter(FileUtils.getExternalFilesDir() + "/" + filename);
BufferedWriter out = new BufferedWriter(fileWriter);
try (BufferedWriter out = new BufferedWriter(new FileWriter(FileUtils.getExternalFilesDir() + "/" + filename))) {
for (UUID uuid : uuids) {
out.write(uuid.toString());
out.newLine();
}
out.close();
} catch (IOException e) {
LOG.warn("can't write app order to file!");
}
@ -199,8 +196,7 @@ public class AppManagerActivity extends AbstractGBFragmentActivity {
static synchronized ArrayList<UUID> getUuidsFromFile(String filename) {
ArrayList<UUID> uuids = new ArrayList<>();
try (FileReader fileReader = new FileReader(FileUtils.getExternalFilesDir() + "/" + filename)) {
BufferedReader in = new BufferedReader(fileReader);
try (BufferedReader in = new BufferedReader(new FileReader(FileUtils.getExternalFilesDir() + "/" + filename))) {
String line;
while ((line = in.readLine()) != null) {
uuids.add(UUID.fromString(line));