public static String getString ( final InputStream is , String encoding ) { if ( is == null ) { return null ; } if ( StringUtils . isNullOrEmptyTrimmed ( encoding ) ) { encoding = UTF_8 ; } final char [ ] buffer = new char [ BUFFER_SIZE ] ; final StringBuilder out = new StringBuilder ( ) ; try { try ( Reader in = new InputStreamReader ( is , encoding ) ) { for ( ; ; ) { int rsz = in . read ( buffer , 0 , buffer . length ) ; if ( rsz < 0 ) { break ; } out . append ( buffer , 0 , rsz ) ; } } } catch ( IOException ioe ) { throw new RuntimeException ( ioe ) ; } return out . toString ( ) ; }
Load input stream into string