aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/util/StreamUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'netx/net/sourceforge/jnlp/util/StreamUtils.java')
-rw-r--r--netx/net/sourceforge/jnlp/util/StreamUtils.java22
1 files changed, 19 insertions, 3 deletions
diff --git a/netx/net/sourceforge/jnlp/util/StreamUtils.java b/netx/net/sourceforge/jnlp/util/StreamUtils.java
index c498b7b..294944a 100644
--- a/netx/net/sourceforge/jnlp/util/StreamUtils.java
+++ b/netx/net/sourceforge/jnlp/util/StreamUtils.java
@@ -42,16 +42,17 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
public class StreamUtils {
- /***
+ /**
* Closes a stream, without throwing IOException.
* In case of IOException, prints the stack trace to System.err.
*
* @param stream the stream that will be closed
*/
- public static void closeSilently (Closeable stream) {
+ public static void closeSilently(Closeable stream) {
if (stream != null) {
try {
stream.close();
@@ -61,8 +62,23 @@ public class StreamUtils {
}
}
+ /**
+ * Copy an input stream's contents into an output stream.
+ */
+ public static void copyStream(InputStream input, OutputStream output)
+ throws IOException {
+ byte[] buffer = new byte[1024];
+ while (true) {
+ int bytesRead = input.read(buffer);
+ if (bytesRead == -1) {
+ break;
+ }
+ output.write(buffer, 0, bytesRead);
+ }
+ }
- public static String readStreamAsString(InputStream stream) throws IOException {
+ public static String readStreamAsString(InputStream stream)
+ throws IOException {
InputStreamReader is = new InputStreamReader(stream);
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(is);