protected TokenCodes findHeaderLength(WsByteBuffer buff) throws MalformedMessageException {

        TokenCodes rc = TokenCodes.TOKEN_RC_MOREDATA;

        if (null == buff) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "findHeaderLength: null buffer provided");
            }
            return rc;
        }

        byte b;
        int numSpaces = 0;
        // start with any pre-existing data
        int length = this.parsedTokenLength;
        while (true) {
            if (this.bytePosition >= this.byteLimit) {
                if (!fillByteCache(buff)) {
                    // no more data
                    break;
                }
            }
            b = this.byteCache[this.bytePosition++];

            // look for the colon marking the end
            if (BNFHeaders.COLON == b) {
                length -= numSpaces; // remove any "trailing" white space

                if (numSpaces > 0) {
                    //PI13987
                    //found trailing whitespace
                    this.foundTrailingWhitespace = true;
                }

                rc = TokenCodes.TOKEN_RC_DELIM;
                break;
            }

            // if we hit whitespace, then keep track of the number of spaces so
            // that we can easily trim that off at the end. This will end up
            // ignoring whitespace that is inside the header name if that does
            // happen

            if (BNFHeaders.SPACE == b || BNFHeaders.TAB == b) {
                numSpaces++;
            } else {
                // reset the counter on any non-space or colon
                numSpaces = 0;
            }

            // check for possible CRLF
            if (BNFHeaders.CR == b || BNFHeaders.LF == b) {
                // Note: would be nice to print the failing data but would need
                // to keep track of where we started inside here, then what about
                // data straddling bytecaches, etc?
                throw new MalformedMessageException("Invalid CRLF found in header name");
            }

            length++;
            // check the limit on a token size
            if (length > this.limitTokenSize) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "findTokenLength: length is too big: " + length);
                }
                throw new MalformedMessageException("Token length: " + length);
            }
        } // end of the while

        this.parsedTokenLength = length;
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "findHeaderLength: " + rc.getName() + "; len=" + length);
        }
        return rc;
    }
protected TokenCodes findHeaderLength ( WsByteBuffer buff ) throws MalformedMessageException { TokenCodes rc = TokenCodes . TOKEN_RC_MOREDATA ; if ( null == buff ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "findHeaderLength: null buffer provided" ) ; } return rc ; } byte b ; int numSpaces = 0 ; int length = this . parsedTokenLength ; while ( true ) { if ( this . bytePosition >= this . byteLimit ) { if ( ! fillByteCache ( buff ) ) { break ; } } b = this . byteCache [ this . bytePosition ++ ] ; if ( BNFHeaders . COLON == b ) { length -= numSpaces ; if ( numSpaces > 0 ) { this . foundTrailingWhitespace = true ; } rc = TokenCodes . TOKEN_RC_DELIM ; break ; } if ( BNFHeaders . SPACE == b || BNFHeaders . TAB == b ) { numSpaces ++ ; } else { numSpaces = 0 ; } if ( BNFHeaders . CR == b || BNFHeaders . LF == b ) { throw new MalformedMessageException ( "Invalid CRLF found in header name" ) ; } length ++ ; if ( length > this . limitTokenSize ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "findTokenLength: length is too big: " + length ) ; } throw new MalformedMessageException ( "Token length: " + length ) ; } } this . parsedTokenLength = length ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "findHeaderLength: " + rc . getName ( ) + "; len=" + length ) ; } return rc ; }
Parse a byte delimited token and return the length of the token.

@param buff
@return TokenCodes (global length variable is set to parsed length)
@throws MalformedMessageException