Add loadToStringBuffer methods.

This commit is contained in:
Christian P. MOMON 2013-08-02 17:21:07 +02:00
parent 931d5f8bb4
commit 0a0f6cd746

View file

@ -270,6 +270,38 @@ public class ToolBox
{ {
String result; 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; BufferedReader in = null;
try try
{ {
@ -277,7 +309,7 @@ public class ToolBox
boolean ended = false; boolean ended = false;
final String LINE_SEPARATOR = System.getProperty("line.separator"); final String LINE_SEPARATOR = System.getProperty("line.separator");
StringBuffer buffer = new StringBuffer((int) file.length()); result = new StringBuffer((int) file.length());
while (!ended) while (!ended)
{ {
String line = in.readLine(); String line = in.readLine();
@ -288,12 +320,9 @@ public class ToolBox
} }
else else
{ {
buffer.append(line).append(LINE_SEPARATOR); result.append(line).append(LINE_SEPARATOR);
} }
} }
//
result = buffer.toString();
} }
finally finally
{ {