public static String load ( Reader reader , Integer ... maxCount ) throws IOException { long maxCountValue = maxCount . length > 0 ? maxCount [ 0 ] : Long . MAX_VALUE ; StringWriter writer = new StringWriter ( ) ; try { char [ ] buffer = new char [ 1024 ] ; for ( ; ; ) { int readChars = reader . read ( buffer , 0 , ( int ) Math . min ( buffer . length , maxCountValue ) ) ; if ( readChars <= 0 ) { break ; } writer . write ( buffer , 0 , readChars ) ; maxCountValue -= readChars ; } } finally { Files . close ( reader ) ; Files . close ( writer ) ; } return writer . toString ( ) ; }
Load string from character stream then closes it .