Allow code that already has a reader to rock right on as well.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2587 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-07-12 20:55:37 +00:00
parent 5c46986b00
commit 9ba1410a46
+23 -15
View File
@@ -91,21 +91,6 @@ public class StreamUtil
}
}
/**
* Reads the contents of the supplied stream into a string using the supplied {@link Charset}.
*/
public static String toString (InputStream stream, String charset)
throws IOException
{
InputStreamReader reader = new InputStreamReader(stream, charset);
char[] inbuf = new char[4096];
StringBuffer outbuf = new StringBuffer();
for (int read = 0; (read = reader.read(inbuf)) > 0; ) {
outbuf.append(inbuf, 0, read);
}
return outbuf.toString();
}
/**
* Copies the contents of the supplied input stream to the supplied output stream.
*/
@@ -117,4 +102,27 @@ public class StreamUtil
out.write(buffer, 0, read);
}
}
/**
* Reads the contents of the supplied stream into a string using the supplied {@link Charset}.
*/
public static String toString (InputStream stream, String charset)
throws IOException
{
return toString(new InputStreamReader(stream, charset));
}
/**
* Reads the contents of the supplied reader into a string.
*/
public static String toString (Reader reader)
throws IOException
{
char[] inbuf = new char[4096];
StringBuffer outbuf = new StringBuffer();
for (int read = 0; (read = reader.read(inbuf)) > 0; ) {
outbuf.append(inbuf, 0, read);
}
return outbuf.toString();
}
}