public static String nextLine(InputStream stream) throws IOException {
        StringBuilder sb = new StringBuilder();
        boolean cr = false;
        for(int read = stream.read();; read = stream.read()){
            if(read == -1)
                throw new EOFException("EOF reached before line ended.");

            char current = (char) read;
            if(current == CR){
                cr = true;
                continue;
            }
            if(cr){
                if(current == LF)
                    break;
                sb.append(CR);
                sb.append(current);
                cr = false;
                continue;
            }else{
                if(current == LF)
                    break;
                sb.append(current);
            }
        }
        return sb.toString();
    }
public static String nextLine ( InputStream stream ) throws IOException { StringBuilder sb = new StringBuilder ( ) ; boolean cr = false ; for ( int read = stream . read ( ) ; ; read = stream . read ( ) ) { if ( read == - 1 ) throw new EOFException ( "EOF reached before line ended." ) ; char current = ( char ) read ; if ( current == CR ) { cr = true ; continue ; } if ( cr ) { if ( current == LF ) break ; sb . append ( CR ) ; sb . append ( current ) ; cr = false ; continue ; } else { if ( current == LF ) break ; sb . append ( current ) ; } } return sb . toString ( ) ; }
@param stream
@return the next line from the stream
@throws IOException