code: public final static int getScalarReadLengthFromBytes(byte[] bytes, int offset, int maxLength)
      {
          int src = offset;
          int end = offset + maxLength;
  
          if (src >= end) throw new ArrayIndexOutOfBoundsException();
          int c = bytes[src++] & 0xff;
          int utf8length = getUTF8LengthFromFirstByte(c);
          if (src + utf8length > end) throw new ArrayIndexOutOfBoundsException();
  
          return utf8length;
      }
docs: this helper calculates the number of bytes it will consume from the
  supplied byte array (bytes) if getScalarFromBytes is called with
  the same parameters.  This is in place of having getScalarFromBytes
  return an object with the bytes consumed and the resultant scalar.
  This will throw ArrayIndexOutOfBoundsException if there are fewer
  bytes remaining (maxLength) than needed for a valid UTF8 sequence
  starting at offset.
  @param bytes UTF8 bytes in user supplied array
  @param offset first array element to read from
  @param maxLength maximum number of bytes to read from the array
  @return number of bytes needed to decode the next scalar