@ Blocking public static String readText ( BufferedReader reader ) throws IOException { StringBuilder answer = new StringBuilder ( ) ; if ( reader == null ) { return answer . toString ( ) ; } // reading the content of the file within a char buffer // allow to keep the correct line endings char [ ] charBuffer = new char [ BUFFER_MAX ] ; int nbCharRead /* = 0*/ ; try { while ( ( nbCharRead = reader . read ( charBuffer ) ) != - 1 ) { // appends buffer answer . append ( charBuffer , 0 , nbCharRead ) ; } Reader temp = reader ; reader = null ; temp . close ( ) ; } finally { try { if ( reader != null ) { reader . close ( ) ; } } catch ( IOException e ) { if ( LOG . isWarnEnabled ( ) ) { LOG . warn ( "Failed to close reader: " + e . getMessage ( ) , e ) ; } } } return answer . toString ( ) ; }
Read the content of the BufferedReader and return it as a String in a blocking manner . The BufferedReader is closed afterwards .