From 69d900c297a2d8aaa7a76635d813fe56aac80a35 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 1 Dec 2014 16:28:00 +0100 Subject: [PATCH] Add loadToStringList(URL) methods. --- src/fr/devinsy/util/FileTools.java | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/fr/devinsy/util/FileTools.java b/src/fr/devinsy/util/FileTools.java index f1712ab..aecb483 100644 --- a/src/fr/devinsy/util/FileTools.java +++ b/src/fr/devinsy/util/FileTools.java @@ -376,6 +376,42 @@ public class FileTools return result; } + /** + * + * @param file + * @return + * @throws IOException + */ + public static StringList loadToStringList(final URL source) throws IOException + { + StringList result; + + final String DEFAULT_CHARSET_NAME = "UTF-8"; + result = loadToStringList(source, DEFAULT_CHARSET_NAME); + + // + return result; + } + + /** + * + * @param file + * @throws IOException + */ + public static StringList loadToStringList(final URL source, final String charsetName) throws IOException + { + StringList result; + + // + result = new StringList(); + + // + read(result, source.openStream(), charsetName); + + // + return result; + } + /** * * @param file @@ -421,6 +457,50 @@ public class FileTools } } + /** + * + * @param file + * @throws IOException + */ + public static void read(final StringList out, final InputStream is, final String charsetName) throws IOException + { + BufferedReader in = null; + try + { + in = new BufferedReader(new InputStreamReader(is, charsetName)); + + boolean ended = false; + + while (!ended) + { + String line = in.readLine(); + + if (line == null) + { + ended = true; + } + else + { + out.append(line); + } + } + } + finally + { + try + { + if (in != null) + { + in.close(); + } + } + catch (IOException exception) + { + exception.printStackTrace(); + } + } + } + /** * * @param source