question: public static String stream2String ( InputStream is , int maxLength ) throws IOException { byte [ ] buffer = new byte [ 4096 ] ; StringWriter sw = new StringWriter ( ) ; int totalRead = 0 ; int read = 0 ; do { sw . write ( new String ( buffer , 0 , read ) ) ; totalRead += read ; read = is . read ( buffer , 0 , buffer . length ) ; } while ( ( ( - 1 == maxLength ) || ( totalRead < maxLength ) ) && ( read != - 1 ) ) ; return sw . toString ( ) ; }
target:  Read a String of up to maxLength bytes from an InputStream