code: public static String getSchemePrefix(String spec) {
          int colon = spec.indexOf(':');
  
          if (colon < 1) {
              return null;
          }
  
          for (int i = 0; i < colon; i++) {
              char c = spec.charAt(i);
              if (!isValidSchemeChar(i, c)) {
                  return null;
              }
          }
  
          return spec.substring(0, colon).toLowerCase(Locale.US);
      }
docs: Returns the scheme prefix like "http" from the URL spec, or null if the
  spec doesn't start with a scheme. Scheme prefixes match this pattern:
  {@code alpha ( alpha | digit | '+' | '-' | '.' )* ':'}