private static String readLine ( InputStream is ) throws IOException { StringBuilder builder = new StringBuilder ( ) ; while ( true ) { int ch = is . read ( ) ; if ( ch == ' ' ) { ch = is . read ( ) ; if ( ch == ' ' ) { break ; } else { throw new IOException ( "unexpected char after \\r: " + ch ) ; } } else if ( ch == - 1 ) { if ( builder . length ( ) > 0 ) { throw new IOException ( "unexpected end of stream" ) ; } break ; } builder . append ( ( char ) ch ) ; } return builder . toString ( ) ; }
Read a \ r \ n terminated line from an InputStream .