Search in sources :

Example 56 with InvalidPathException

use of java.nio.file.InvalidPathException in project jdk8u_jdk by JetBrains.

the class WindowsPathParser method normalize.

/**
     * Remove redundant slashes from the rest of the path, forcing all slashes
     * into the preferred slash.
    */
private static String normalize(StringBuilder sb, String path, int off) {
    int len = path.length();
    off = nextNonSlash(path, off, len);
    int start = off;
    char lastC = 0;
    while (off < len) {
        char c = path.charAt(off);
        if (isSlash(c)) {
            if (lastC == ' ')
                throw new InvalidPathException(path, "Trailing char <" + lastC + ">", off - 1);
            sb.append(path, start, off);
            off = nextNonSlash(path, off, len);
            if (//no slash at the end of normalized path
            off != len)
                sb.append('\\');
            start = off;
        } else {
            if (isInvalidPathChar(c))
                throw new InvalidPathException(path, "Illegal char <" + c + ">", off);
            lastC = c;
            off++;
        }
    }
    if (start != off) {
        if (lastC == ' ')
            throw new InvalidPathException(path, "Trailing char <" + lastC + ">", off - 1);
        sb.append(path, start, off);
    }
    return sb.toString();
}
Also used : InvalidPathException(java.nio.file.InvalidPathException)

Example 57 with InvalidPathException

use of java.nio.file.InvalidPathException in project jdk8u_jdk by JetBrains.

the class WindowsPathParser method parse.

/**
     * Parses the given input as a Windows path.
     *
     * @param   requireToNormalize
     *          Indicates if the path requires to be normalized
     */
private static Result parse(String input, boolean requireToNormalize) {
    String root = "";
    WindowsPathType type = null;
    int len = input.length();
    int off = 0;
    if (len > 1) {
        char c0 = input.charAt(0);
        char c1 = input.charAt(1);
        char c = 0;
        int next = 2;
        if (isSlash(c0) && isSlash(c1)) {
            // UNC: We keep the first two slash, collapse all the
            // following, then take the hostname and share name out,
            // meanwhile collapsing all the redundant slashes.
            type = WindowsPathType.UNC;
            off = nextNonSlash(input, next, len);
            next = nextSlash(input, off, len);
            if (off == next)
                throw new InvalidPathException(input, "UNC path is missing hostname");
            //host
            String host = input.substring(off, next);
            off = nextNonSlash(input, next, len);
            next = nextSlash(input, off, len);
            if (off == next)
                throw new InvalidPathException(input, "UNC path is missing sharename");
            root = "\\\\" + host + "\\" + input.substring(off, next) + "\\";
            off = next;
        } else {
            if (isLetter(c0) && c1 == ':') {
                char c2;
                if (len > 2 && isSlash(c2 = input.charAt(2))) {
                    // avoid concatenation when root is "D:\"
                    if (c2 == '\\') {
                        root = input.substring(0, 3);
                    } else {
                        root = input.substring(0, 2) + '\\';
                    }
                    off = 3;
                    type = WindowsPathType.ABSOLUTE;
                } else {
                    root = input.substring(0, 2);
                    off = 2;
                    type = WindowsPathType.DRIVE_RELATIVE;
                }
            }
        }
    }
    if (off == 0) {
        if (len > 0 && isSlash(input.charAt(0))) {
            type = WindowsPathType.DIRECTORY_RELATIVE;
            root = "\\";
        } else {
            type = WindowsPathType.RELATIVE;
        }
    }
    if (requireToNormalize) {
        StringBuilder sb = new StringBuilder(input.length());
        sb.append(root);
        return new Result(type, root, normalize(sb, input, off));
    } else {
        return new Result(type, root, input);
    }
}
Also used : InvalidPathException(java.nio.file.InvalidPathException)

Example 58 with InvalidPathException

use of java.nio.file.InvalidPathException in project jdk8u_jdk by JetBrains.

the class DiacriticTest method main.

public static void main(String[] args) throws IOException {
    if (!isMacOSX) {
        System.out.println("This test is for Mac OS X only. Passing.");
        return;
    }
    String lang = System.getenv("LANG");
    if (lang != null && !lang.contains("UTF-8")) {
        System.out.println("LANG variable set to the language that " + "does not support unicode, test passes vacuously");
        return;
    }
    File sourceFile = new File(NAME_NFC + ".java");
    String source = "public class " + NAME_NFC + " { " + "    public static void main(String args[]) {\n" + "        System.out.println(\"Success!\");\n" + "    }\n" + "}\n";
    ArrayList<String> content = new ArrayList<>();
    content.add(source);
    try {
        createFile(sourceFile, content);
    } catch (UnmappableCharacterException | InvalidPathException ipe) {
        System.out.println("The locale or file system is configured in a way " + "that prevents file creation. Real testing impossible.");
        return;
    }
    HashMap<String, String> env = new HashMap<>();
    env.put("LC_CTYPE", "UTF-8");
    TestResult tr;
    tr = doExec(env, javacCmd, NAME_NFD + ".java");
    System.out.println(tr.testOutput);
    if (!tr.isOK()) {
        System.out.println(tr);
        throw new RuntimeException("Compilation failed");
    }
    tr = doExec(env, javaCmd, "-cp", ".", NAME_NFD);
    System.out.println(tr.testOutput);
    if (!tr.isOK()) {
        System.out.println(tr);
        throw new RuntimeException("Test execution failed");
    }
}
Also used : HashMap(java.util.HashMap) UnmappableCharacterException(java.nio.charset.UnmappableCharacterException) ArrayList(java.util.ArrayList) File(java.io.File) InvalidPathException(java.nio.file.InvalidPathException)

Example 59 with InvalidPathException

use of java.nio.file.InvalidPathException in project lucene-solr by apache.

the class MockFileSystemTestCase method implTestURI.

private void implTestURI(String fileName) throws IOException {
    assumeFalse("broken on J9: see https://issues.apache.org/jira/browse/LUCENE-6517", Constants.JAVA_VENDOR.startsWith("IBM"));
    Path dir = wrap(createTempDir());
    try {
        dir.resolve(fileName);
    } catch (InvalidPathException ipe) {
        assumeNoException("couldn't resolve '" + fileName + "'", ipe);
    }
    Path f1 = dir.resolve(fileName);
    URI uri = f1.toUri();
    Path f2 = dir.getFileSystem().provider().getPath(uri);
    assertEquals(f1, f2);
    dir.getFileSystem().close();
}
Also used : Path(java.nio.file.Path) URI(java.net.URI) InvalidPathException(java.nio.file.InvalidPathException)

Example 60 with InvalidPathException

use of java.nio.file.InvalidPathException in project jdk8u_jdk by JetBrains.

the class ProxyClassesDumper method dumpClass.

public void dumpClass(String className, final byte[] classBytes) {
    Path file;
    try {
        file = dumpDir.resolve(encodeForFilename(className) + ".class");
    } catch (InvalidPathException ex) {
        PlatformLogger.getLogger(ProxyClassesDumper.class.getName()).warning("Invalid path for class " + className);
        return;
    }
    try {
        Path dir = file.getParent();
        Files.createDirectories(dir);
        Files.write(file, classBytes);
    } catch (Exception ignore) {
        PlatformLogger.getLogger(ProxyClassesDumper.class.getName()).warning("Exception writing to path at " + file.toString());
    // simply don't care if this operation failed
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)111 Path (java.nio.file.Path)58 IOException (java.io.IOException)30 File (java.io.File)17 URL (java.net.URL)15 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 ArrayList (java.util.ArrayList)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 BufferedReader (java.io.BufferedReader)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4