Пример #1
0
  /**
   * Construct a path from a String. Path strings are URIs, but with unescaped elements and some
   * additional normalization.
   */
  public Path(String pathString) {
    checkPathArg(pathString);

    // We can't use 'new URI(String)' directly, since it assumes things are
    // escaped, which we don't require of Paths.

    // add a slash in front of paths with Windows drive letters
    if (hasWindowsDrive(pathString, false)) pathString = "/" + pathString;

    // parse uri components
    String scheme = null;
    String authority = null;

    int start = 0;

    // parse uri scheme, if any
    int colon = pathString.indexOf(':');
    int slash = pathString.indexOf('/');
    if ((colon != -1) && ((slash == -1) || (colon < slash))) { // has a scheme
      scheme = pathString.substring(0, colon);
      start = colon + 1;
    }

    // parse uri authority, if any
    if (pathString.startsWith("//", start) && (pathString.length() - start > 2)) { // has authority
      int nextSlash = pathString.indexOf('/', start + 2);
      int authEnd = nextSlash > 0 ? nextSlash : pathString.length();
      authority = pathString.substring(start + 2, authEnd);
      start = authEnd;
    }

    // uri path is the rest of the string -- query & fragment not supported
    String path = pathString.substring(start, pathString.length());

    initialize(scheme, authority, path, null);
  }
Пример #2
0
 /** Construct a Path from components. */
 public Path(String scheme, String authority, String path) {
   checkPathArg(path);
   initialize(scheme, authority, path, null);
 }