diff --git a/src/dorkbox/util/FileUtil.java b/src/dorkbox/util/FileUtil.java index 12b6121..087e7e3 100644 --- a/src/dorkbox/util/FileUtil.java +++ b/src/dorkbox/util/FileUtil.java @@ -154,19 +154,41 @@ class FileUtil { /** * Reads the contents of the supplied input stream into a list of lines. - * Closes the reader on successful or failed completion. + * + * @return Always returns a list, even if the file does not exist, or there are errors reading it. */ public static - List readLines(Reader in) throws IOException { + List readLines(final File file) { + FileReader fileReader = null; + try { + fileReader = new FileReader(file); + } catch (FileNotFoundException ignored) { + return new ArrayList(); + } + return readLines(fileReader); + } + + /** + * Reads the contents of the supplied input stream into a list of lines. + *

+ * Closes the reader on successful or failed completion. + * + * @return Always returns a list, even if the file does not exist, or there are errors reading it. + */ + public static + List readLines(Reader in) { List lines = new ArrayList(); try { BufferedReader bin = new BufferedReader(in); String line; - while ((line = bin.readLine()) != null) { - lines.add(line); + try { + while ((line = bin.readLine()) != null) { + lines.add(line); + } + } catch (IOException ignored) { } } finally { - IO.close(in); + IO.closeQuietly(in); } return lines; }