Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cf3c7fc authored by lijilou's avatar lijilou Committed by Jilou li
Browse files

close the opend resources when IOException happen.

Bug: none
Flag: EXEMPT minor optimization
Change-Id: I987f4cb7d84af0561d75b494549c7bc2868e0d0f
parent f920cc5d
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -245,18 +245,20 @@ public class TaskPersister implements PersisterQueue.Listener {

    private static String fileToString(File file) {
        final String newline = System.lineSeparator();
        BufferedReader reader = null;
        try {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            reader = new BufferedReader(new FileReader(file));
            StringBuffer sb = new StringBuffer((int) file.length() * 2);
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line + newline);
            }
            reader.close();
            return sb.toString();
        } catch (IOException ioe) {
            Slog.e(TAG, "Couldn't read file " + file.getName());
            return null;
        } finally {
            IoUtils.closeQuietly(reader);
        }
    }