Code example for URI

Methods: getSchemegetSchemeSpecificParttoString

0
   *  
   * @param uri the URI to be used to create the indexable source 
   * @return a representation of the data source represented by the given URI 
   */ 
  public static IndexableSource from(URI uri) {
    String scheme = uri.getScheme();
    if (scheme.equals(FILE_SCHEME)) {
      return new FileSource(new File(uri));
    } else if (scheme.equals(JAR_SCHEME)) {
      String entrySpecification = uri.getSchemeSpecificPart();
      int index = entrySpecification.indexOf(JAR_SUFFIX);
      if (index < 0) {
        throw new IllegalArgumentException("Invalid jar URI syntax: " + uri.toString());
      } 
      String fileUri = entrySpecification.substring(0, index);
      String entryPath = entrySpecification.substring(index + JAR_SUFFIX.length());
      if (fileUri.length() == 0) {
        throw new IllegalArgumentException("Invalid jar URI syntax - missing jar file URI: "
            + uri.toString());
      } else if (entryPath.length() == 0) {
        throw new IllegalArgumentException("Invalid jar URI syntax - missing entry path: "
            + uri.toString());
      } 
      try { 
        return new JarSource(new File(new URI(fileUri)), entryPath);
      } catch (URISyntaxException exception) {
        if (fileUri.length() == 0 || entryPath.length() == 0) {
          throw new IllegalArgumentException("Invalid jar URI syntax - invalid jar file URI: "
              + uri.toString(), exception);
        } 
      } 
    } 
    throw new IllegalArgumentException("Cannot create indexable source from URI: " + uri.toString());
  } 
 
  /** 
   * Return the file extension for this source. 
   *  
Contextual code suggestions in your IDE  Get Codota for Java