View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.testframework;
5   
6   import java.io.IOException;
7   import java.io.InputStream;
8   
9   import org.apache.commons.io.IOUtils;
10  
11  
12  public class StreamUtil {
13  
14  	public static String toString(InputStream in) {
15  		if (in == null) {
16  			throw new NullPointerException("no input stream given");
17  		}
18  
19  		StringBuilder sb = new StringBuilder();
20  		int c;
21  		try {
22  			while ((c = in.read()) != -1) {
23  				sb.append((char) c);
24  			}
25  		} catch (IOException e) {
26  			// ignored
27  		} finally {
28  			IOUtils.closeQuietly(in);
29  		}
30  		return sb.toString();
31  	}
32  
33  }