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) {
|
static synchronized void rewriteAppOrderFile(String filename, List<UUID> uuids) {
|
||||||
try {
|
try (BufferedWriter out = new BufferedWriter(new FileWriter(FileUtils.getExternalFilesDir() + "/" + filename))) {
|
||||||
FileWriter fileWriter = new FileWriter(FileUtils.getExternalFilesDir() + "/" + filename);
|
|
||||||
BufferedWriter out = new BufferedWriter(fileWriter);
|
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
out.write(uuid.toString());
|
out.write(uuid.toString());
|
||||||
out.newLine();
|
out.newLine();
|
||||||
}
|
}
|
||||||
out.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warn("can't write app order to file!");
|
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) {
|
static synchronized ArrayList<UUID> getUuidsFromFile(String filename) {
|
||||||
ArrayList<UUID> uuids = new ArrayList<>();
|
ArrayList<UUID> uuids = new ArrayList<>();
|
||||||
try (FileReader fileReader = new FileReader(FileUtils.getExternalFilesDir() + "/" + filename)) {
|
try (BufferedReader in = new BufferedReader(new FileReader(FileUtils.getExternalFilesDir() + "/" + filename))) {
|
||||||
BufferedReader in = new BufferedReader(fileReader);
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
uuids.add(UUID.fromString(line));
|
uuids.add(UUID.fromString(line));
|
||||||
|
|
Loading…
Reference in New Issue