public String readLine()

in src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedReader.java [333:402]


    public String readLine() throws IOException {
        checkOpen();
        /* has the underlying stream been exhausted? */
        if (pos == end && fillBuf() == EOF) {
            return null;
        }
        for (int charPos = pos; charPos < end; charPos++) {
            final char ch = buf[charPos];
            if (ch > CR) {
                continue;
            }
            if (ch == LF) {
                final String res = new String(buf, pos, charPos - pos);
                pos = charPos + 1;
                return res;
            }
            if (ch == CR) {
                final String res = new String(buf, pos, charPos - pos);
                pos = charPos + 1;
                if ((pos < end || fillBuf() != EOF) && buf[pos] == LF) {
                    pos++;
                }
                return res;
            }
        }

        char eol = NUL;
        final StringBuilder result = new StringBuilder(80);
        /* Typical Line Length */

        result.append(buf, pos, end - pos);
        while (true) {
            pos = end;

            /* Are there buffered characters available? */
            if (eol == LF) {
                return result.toString();
            }
            // attempt to fill buffer
            if (fillBuf() == EOF) {
                // characters or null.
                return result.length() > 0 || eol != NUL ? result.toString() : null;
            }
            for (int charPos = pos; charPos < end; charPos++) {
                final char c = buf[charPos];
                if (eol != NUL) {
                    if (eol == CR && c == LF) {
                        if (charPos > pos) {
                            result.append(buf, pos, charPos - pos - 1);
                        }
                        pos = charPos + 1;
                    } else {
                        if (charPos > pos) {
                            result.append(buf, pos, charPos - pos - 1);
                        }
                        pos = charPos;
                    }
                    return result.toString();
                }
                if (c == LF || c == CR) {
                    eol = c;
                }
            }
            if (eol == NUL) {
                result.append(buf, pos, end - pos);
            } else {
                result.append(buf, pos, end - pos - 1);
            }
        }
    }