class IOChannelUtils {

  public static IOChannelFactory getFactory(String spec) throws IOException {
    // The spec is almost, but not quite, a URI. In particular,
    // the reserved characters '[', ']', and '?' have meanings that differ
    // from their use in the URI spec. ('*' is not reserved).
    // Here, we just need the scheme, which is so circumscribed as to be
    // very easy to extract with a regex.
    Matcher matcher = URI_SCHEME_PATTERN.matcher(spec);

    if (!matcher.matches()) {
      return FileIOChannelFactory.fromOptions(null);
    }

    String scheme = matcher.group("scheme");
    IOChannelFactory ioFactory = FACTORY_MAP.get(scheme);
    if (ioFactory != null) {
      return ioFactory;
    }

    throw new IOException("Unable to find handler for " + spec);
  }

}