code: public final static int getScalarFromBytes(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();
  
          switch (utf8length) {
          case 1:
              break;
          case 2:
              c  = (c & UNICODE_TWO_BYTE_MASK);
              c |= ((bytes[src++] & 0xff) & UNICODE_CONTINUATION_BYTE_MASK);
              break;
          case 3:
              c  = (c & UNICODE_THREE_BYTE_MASK);
              c |= ((bytes[src++] & 0xff) & UNICODE_CONTINUATION_BYTE_MASK);
              c |= ((bytes[src++] & 0xff) & UNICODE_CONTINUATION_BYTE_MASK);
              break;
          case 4:
              c  = (c & UNICODE_FOUR_BYTE_MASK);
              c |= ((bytes[src++] & 0xff) & UNICODE_CONTINUATION_BYTE_MASK);
              c |= ((bytes[src++] & 0xff) & UNICODE_CONTINUATION_BYTE_MASK);
              c |= ((bytes[src++] & 0xff) & UNICODE_CONTINUATION_BYTE_MASK);
              break;
          default:
              throw new InvalidUnicodeCodePoint("code point is invalid: "+utf8length);
          }
          return c;
      }
docs: this helper converts the bytes starting at offset from UTF8 to a
  Unicode scalar.  This does not check for valid Unicode scalar ranges
  but simply handle the UTF8 decoding.  getScalarReadLengthFromBytes
  can be used to determine how many bytes would be converted (consumed) in
  this process if the same parameters are passed in.  This will throw
  ArrayIndexOutOfBoundsException if the array has too few bytes to
  fully decode the scalar. It will throw InvalidUnicodeCodePoint if
  the first byte isn't a valid UTF8 initial byte with a length of
  4 or less.
  @param bytes UTF8 bytes in an array
  @param offset initial array element to decode from
  @param maxLength maximum number of bytes to consume from the array
  @return Unicode scalar