Add loadToStringList(URL) methods.

This commit is contained in:
Christian P. MOMON 2014-12-01 16:28:00 +01:00
parent 8a996fc491
commit 69d900c297

View file

@ -376,6 +376,42 @@ public class FileTools
return result; 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 * @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 * @param source