@ Override public boolean parseBinaryFirstLine ( WsByteBuffer buff ) throws MalformedMessageException { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "parseBinaryFirstLine for " + this ) ; Tr . debug ( tc , "Buffer: " + buff ) ; } // check the version first if we need to if ( getBinaryParseState ( ) == HttpInternalConstants . PARSING_BINARY_VERSION ) { if ( ! buff . hasRemaining ( ) ) { return false ; } byte version = buff . get ( ) ; if ( version != HttpInternalConstants . BINARY_TRANSPORT_V1 ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "Unsupported binary version in message: " + version ) ; } throw new MalformedMessageException ( "Invalid binary message" ) ; } setBinaryParseState ( HttpInternalConstants . PARSING_VERSION_ID_OR_LEN ) ; resetCacheToken ( 4 ) ; } // stop parsing the FirstLine when we have parsed the status or the // reason header or we hit the end of the buffer and need to read more boolean lineEnds = false ; int value ; while ( ! lineEnds ) { // at this point, the parsed token array is always set up, so we // can try to fill it now if ( ! fillCacheToken ( buff ) ) { return false ; } switch ( getBinaryParseState ( ) ) { case HttpInternalConstants . PARSING_VERSION_ID_OR_LEN : value = GenericUtils . asInt ( getParsedToken ( ) ) ; if ( 0 == ( value & GenericConstants . KNOWN_MASK ) ) { // known version ordinal setVersion ( VersionValues . getByOrdinal ( value ) ) ; setBinaryParseState ( HttpInternalConstants . PARSING_STATUS ) ; resetCacheToken ( 4 ) ; } else { // unknown version length setBinaryParseState ( HttpInternalConstants . PARSING_UNKNOWN_VERSION ) ; resetCacheToken ( value & GenericConstants . UNKNOWN_MASK ) ; } break ; case HttpInternalConstants . PARSING_UNKNOWN_VERSION : setVersion ( VersionValues . find ( getParsedToken ( ) ) ) ; setBinaryParseState ( HttpInternalConstants . PARSING_STATUS ) ; createCacheToken ( 4 ) ; break ; case HttpInternalConstants . PARSING_STATUS : setStatusCode ( GenericUtils . asInt ( getParsedToken ( ) ) ) ; setBinaryParseState ( HttpInternalConstants . PARSING_REASON_LEN ) ; resetCacheToken ( 4 ) ; break ; case HttpInternalConstants . PARSING_REASON_LEN : value = GenericUtils . asInt ( getParsedToken ( ) ) ; if ( 0 == value ) { // end of first line response headers setBinaryParseState ( GenericConstants . PARSING_HDR_FLAG ) ; resetCacheToken ( 4 ) ; lineEnds = true ; } else { setBinaryParseState ( HttpInternalConstants . PARSING_REASON ) ; resetCacheToken ( value ) ; } break ; case HttpInternalConstants . PARSING_REASON : setReasonPhrase ( getParsedToken ( ) ) ; setBinaryParseState ( GenericConstants . PARSING_HDR_FLAG ) ; createCacheToken ( 4 ) ; lineEnds = true ; break ; default : throw new MalformedMessageException ( "Invalid state in line: " + getBinaryParseState ( ) ) ; } // end of switch } // end of while loop setFirstLineComplete ( true ) ; return true ; }
Begin parsing line out from a given buffer . Returns boolean as to whether it has found the end of the first line .