Code example for BufferUnderflowException

0
 
        ByteBuffer input = source.duplicate();
 
        // Do we have a complete header? 
        if (input.remaining() < RECORD_HEADER_SIZE) {
            throw new BufferUnderflowException();
        } 
 
        // Is it a handshake message? 
        byte firstByte = input.get();
        /*byte secondByte =*/ input.get();
        byte thirdByte = input.get();
        if ((firstByte & 0x80) != 0 && thirdByte == 0x01) {
            // looks like a V2ClientHello 
            // return (((firstByte & 0x7F) << 8) | (secondByte & 0xFF)) + 2; 
            return RECORD_HEADER_SIZE;   // Only need the header fields
        } else { 
            return (((input.get() & 0xFF) << 8) | (input.get() & 0xFF)) + 5;
        } 
    } 
Experience pair programming with AI  Get Codota for Java