public int read()

in src/main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java [89:148]


    public int read() throws IOException {
        synchronized (lock) {
            if (eof) {
                return NetConstants.EOS; // Don't allow read past EOF
            }
            int chint = super.read();
            if (chint == NetConstants.EOS) { // True EOF
                eof = true;
                return NetConstants.EOS;
            }
            if (atBeginning) {
                atBeginning = false;
                if (chint == DOT) { // Have DOT
                    mark(2); // need to check for CR LF or DOT
                    chint = super.read();
                    switch (chint) {
                    case NetConstants.EOS:
                        // new Throwable("Trailing DOT").printStackTrace();
                        eof = true;
                        return DOT; // return the trailing DOT
                    case DOT:
                        // no need to reset as we want to lose the first DOT
                        return chint; // i.e. DOT
                    case CR:
                        chint = super.read();
                        if (chint == NetConstants.EOS) { // Still only DOT CR - should not happen
                            // new Throwable("Trailing DOT CR").printStackTrace();
                            reset(); // So CR is picked up next time
                            return DOT; // return the trailing DOT
                        }
                        if (chint == LF) { // DOT CR LF
                            atBeginning = true;
                            eof = true;
                            // Do we need to clear the mark somehow?
                            return NetConstants.EOS;
                        }
                        break;
                    default:
                        break;
                    }
                    // Should not happen - lone DOT at beginning
                    // new Throwable("Lone DOT followed by "+(char)chint).printStackTrace();
                    reset();
                    return DOT;
                } // have DOT
            } // atBeginning

            // Handle CRLF in normal flow
            if (seenCR) {
                seenCR = false;
                if (chint == LF) {
                    atBeginning = true;
                }
            }
            if (chint == CR) {
                seenCR = true;
            }
            return chint;
        }
    }