Author: asoldano
Date: 2014-02-28 06:43:44 -0500 (Fri, 28 Feb 2014)
New Revision: 18443
Modified:
common/trunk/src/main/java/org/jboss/ws/common/IOUtils.java
Log:
[JBWS-3769] Adding utility method
Modified: common/trunk/src/main/java/org/jboss/ws/common/IOUtils.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/IOUtils.java 2014-02-27 16:23:31 UTC
(rev 18442)
+++ common/trunk/src/main/java/org/jboss/ws/common/IOUtils.java 2014-02-28 11:43:44 UTC
(rev 18443)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2014, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -21,11 +21,13 @@
*/
package org.jboss.ws.common;
+import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
@@ -53,6 +55,30 @@
{
return new OutputStreamWriter(new FileOutputStream(file), charset);
}
+
+ public static String readAndCloseStream(InputStream is) throws IOException
+ {
+ return readAndCloseStream(is, "UTF-8");
+ }
+
+ public static String readAndCloseStream(InputStream is, String charsetName) throws
IOException
+ {
+ final StringBuilder sb = new StringBuilder();
+ final BufferedReader br = new BufferedReader(new InputStreamReader(is,
charsetName));
+ String line;
+ try
+ {
+ while ((line = br.readLine()) != null)
+ {
+ sb.append(line);
+ }
+ }
+ finally
+ {
+ br.close();
+ }
+ return sb.toString();
+ }
/** Copy the input stream to the output stream
*/