Package java.nio.file

Examples of java.nio.file.InvalidPathException


  }

  private static void checkValid(String path) {
    int nulIndex = path.indexOf('\0');
    if (nulIndex != -1) {
      throw new InvalidPathException(path, "nul character not allowed", nulIndex);
    }
  }
View Full Code Here


  public ParseResult parsePath(String path) {
    String original = path;
    path = path.replace('/', '\\');

    if (WORKING_DIR_WITH_DRIVE.matcher(path).matches()) {
      throw new InvalidPathException(original, "Jimfs does not currently support the Windows "
          + "syntax for a relative path on a specific drive (e.g. \"C:foo\\bar\"");
    }

    String root;
    if (path.startsWith("\\\\")) {
      root = parseUncRoot(path, original);
    } else if (path.startsWith("\\")) {
      throw new InvalidPathException(original, "Jimfs does not currently support the Windows "
          + "syntax for an absolute path on the current drive (e.g. \"\\foo\\bar\"");
    } else {
      root = parseDriveRoot(path);
    }

    // check for root.length() > 3 because only "C:\" type roots are allowed to have :
    int startIndex = root == null || root.length() > 3 ? 0 : root.length();
    for (int i = startIndex; i < path.length(); i++) {
      char c = path.charAt(i);
      if (isReserved(c)) {
        throw new InvalidPathException(original, "Illegal char <" + c + ">", i);
      }
    }

    Matcher trailingSpaceMatcher = TRAILING_SPACES.matcher(path);
    if (trailingSpaceMatcher.find()) {
      throw new InvalidPathException(original, "Trailing char < >", trailingSpaceMatcher.start());
    }

    if (root != null) {
      path = path.substring(root.length());
View Full Code Here

  private String parseUncRoot(String path, String original) {
    Matcher uncMatcher = UNC_ROOT.matcher(path);
    if (uncMatcher.find()) {
      String host = uncMatcher.group(2);
      if (host == null) {
        throw new InvalidPathException(original, "UNC path is missing hostname");
      }
      String share = uncMatcher.group(3);
      if (share == null) {
        throw new InvalidPathException(original, "UNC path is missing sharename");
      }

      return path.substring(uncMatcher.start(), uncMatcher.end());
    } else {
      // probably shouldn't ever reach this
      throw new InvalidPathException(original, "Invalid UNC path");
    }
  }
View Full Code Here

TOP

Related Classes of java.nio.file.InvalidPathException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.