void gatherOp ( int maxPos ) throws IOException { try { while ( this . bufferPosition < maxPos ) { byte b = this . buffer [ this . bufferPosition ] ; this . bufferPosition ++ ; if ( gotCR ) { if ( b == NatsConnection . LF ) { // Got CRLF, jump to parsing this . op = opFor ( opArray , opPos ) ; this . gotCR = false ; this . opPos = 0 ; this . mode = Mode . PARSE_PROTO ; break ; } else { throw new IllegalStateException ( "Bad socket data, no LF after CR" ) ; } } else if ( b == SPACE || b == TAB ) { // Got a space, get the rest of the protocol line this . op = opFor ( opArray , opPos ) ; this . opPos = 0 ; if ( this . op == NatsConnection . OP_MSG ) { this . msgLinePosition = 0 ; this . mode = Mode . GATHER_MSG_PROTO ; } else { this . mode = Mode . GATHER_PROTO ; } break ; } else if ( b == NatsConnection . CR ) { this . gotCR = true ; } else { this . opArray [ opPos ] = ( char ) b ; this . opPos ++ ; } } } catch ( ArrayIndexOutOfBoundsException | IllegalStateException | NumberFormatException | NullPointerException ex ) { this . encounteredProtocolError ( ex ) ; } }
Gather the op either up to the first space or the first carraige return .