public static
String
readTextStream(
- final InputStream input,
- String encoding
+ final InputStream input,
+ String encoding
)
throws IOException
{
- Assert.notNull( input );
+ Assert.notNull( input );
Reader in = null;
// if encoding is not set then use default encoding
try {
return getString( new BufferedReader(
- in = new InputStreamReader( input, encoding ),
- BUFFER_SIZE
+ in = new InputStreamReader( input, encoding ),
+ BUFFER_SIZE
) );
} finally {
tryClose( in );
File fromDir = new File(from);
File toDir = new File(to);
if (fromDir.exists() == false) {
- logger.warn( "Directory {} does not exist.", fromDir.getCanonicalPath() );
+ logger.warn( "Directory {} does not exist.", fromDir.getCanonicalPath() );
return;
}
checkDirectory(fromDir, toDir);
* @throws IOException
*/
public static String readFromFile(URL source) throws IOException {
- char[] chars = new char[4092];
- InputStreamReader contentsReader = null;
- StringBuffer buffer = new StringBuffer();
if (!new java.io.File(source.getFile()).exists()) {
throw new FileNotFoundException();
} else {
- contentsReader = new InputStreamReader(source.openStream());
- int c;
- do {
- c = contentsReader.read(chars);
- if (c == -1)
- {
- break;
- }
- buffer.append(chars, 0, c);
- } while (c != -1);
- contentsReader.close();
+ return readFromFile(source.openStream());
}
+ }
+
+ /**
+ * This method takes a InputStream as parameter to read the contents, and to add
+ * into a string buffer.
+ *
+ * @param source
+ * InputStream to read the contents.
+ * @return string, contents of a file from inputstream.
+ * @throws IOException
+ */
+ public static String readFromFile(InputStream in) throws IOException {
+ char[] chars = new char[4092];
+ InputStreamReader contentsReader = null;
+ StringBuffer buffer = new StringBuffer();
+ contentsReader = new InputStreamReader(in);
+ int c;
+ do {
+ c = contentsReader.read(chars);
+ if (c == -1)
+ {
+ break;
+ }
+ buffer.append(chars, 0, c);
+ } while (c != -1);
+ tryClose(contentsReader);
return buffer.toString();
}