From 0a0f6cd746daa098ae60c6e8132bb0bff4613495 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 2 Aug 2013 17:21:07 +0200 Subject: [PATCH] Add loadToStringBuffer methods. --- src/fr/devinsy/util/ToolBox.java | 39 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/fr/devinsy/util/ToolBox.java b/src/fr/devinsy/util/ToolBox.java index b2d749f..a090e33 100644 --- a/src/fr/devinsy/util/ToolBox.java +++ b/src/fr/devinsy/util/ToolBox.java @@ -270,6 +270,38 @@ public class ToolBox { String result; + result = loadToStringBuffer(file, charsetName).toString(); + + // + return result; + } + + /** + * + * @param file + * @return + * @throws IOException + */ + static public StringBuffer loadToStringBuffer(final File file) throws IOException + { + StringBuffer result; + + final String DEFAULT_CHARSET_NAME = "UTF-8"; + result = loadToStringBuffer(file, DEFAULT_CHARSET_NAME); + + // + return result; + } + + /** + * + * @param file + * @throws IOException + */ + public static StringBuffer loadToStringBuffer(final File file, final String charsetName) throws IOException + { + StringBuffer result; + BufferedReader in = null; try { @@ -277,7 +309,7 @@ public class ToolBox boolean ended = false; final String LINE_SEPARATOR = System.getProperty("line.separator"); - StringBuffer buffer = new StringBuffer((int) file.length()); + result = new StringBuffer((int) file.length()); while (!ended) { String line = in.readLine(); @@ -288,12 +320,9 @@ public class ToolBox } else { - buffer.append(line).append(LINE_SEPARATOR); + result.append(line).append(LINE_SEPARATOR); } } - - // - result = buffer.toString(); } finally {