mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 19:45:50 +01:00
Use try-with-resources to ensure stream is closed on exception
This commit is contained in:
parent
6ed40a21c6
commit
589945f234
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user