public static String copyToString ( InputStream in , Charset charset ) throws IOException { Assert . notNull ( in , "No InputStream specified" ) ; StringBuilder out = new StringBuilder ( ) ; InputStreamReader reader = new InputStreamReader ( in , charset ) ; char [ ] buffer = new char [ BUFFER_SIZE ] ; int bytesRead = - 1 ; while ( ( bytesRead = reader . read ( buffer ) ) != - 1 ) { out . append ( buffer , 0 , bytesRead ) ; } return out . toString ( ) ; }
Copy the contents of the given InputStream into a String . Leaves the stream open when done .