private static ReadableLogRecord doByteByByteScanning ( ByteBuffer sourceBuffer , long expectedSequenceNumber ) { if ( tc . isEntryEnabled ( ) ) Tr . entry ( tc , "doByteByByteScanning" , new Object [ ] { sourceBuffer , new Long ( expectedSequenceNumber ) } ) ; ReadableLogRecord logRecord = null ; ByteBuffer viewBuffer = sourceBuffer . slice ( ) ; // If there is a partial write, or a missing record, the next valid record will be at least LogRecord.HEADER_SIZE // forward from the current position so skip to that in the viewBuffer and start from there. for ( int position = LogRecord . HEADER_SIZE ; position + LogRecord . HEADER_SIZE < viewBuffer . limit ( ) ; // its possible we will be able to find a record in the remainder position ++ ) { viewBuffer . position ( position ) ; // Peak 2 bytes to get RC in RCRD before bothering to try parse a Record. // This saves stack frames and avoids some Exceptions which should help with startup times byte peak = viewBuffer . get ( position ) ; if ( peak == 82 ) // 'R' { peak = viewBuffer . get ( position + 1 ) ; if ( peak == 67 ) // C - its a kinda magic, worth having a go. { try { logRecord = read ( viewBuffer , expectedSequenceNumber , sourceBuffer ) ; if ( logRecord != null ) break ; // we found a valid record, sourceBuffer position has been updated } catch ( RuntimeException e ) { // No FFDC code needed // continue till the end of the loop } } } } if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "doByteByByteScanning" , logRecord ) ; return logRecord ; }
careful with trace in this methods loop