Search in sources :

Example 41 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testNTFSFileEncodedDataStreamAlias.

/**
     * NTFS Alternative Data / File Streams.
     * <p>
     * See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364404(v=vs.85).aspx
     * @throws Exception failed test
     */
@Test
public void testNTFSFileEncodedDataStreamAlias() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path path = dir.resolve("testfile");
    Files.createFile(path);
    try (Resource base = newResource(dir.toFile())) {
        Resource resource = base.addPath("testfile");
        assertThat("resource.alias", resource, hasNoAlias());
        assertThat("resource.uri.alias", newResource(resource.getURI()), hasNoAlias());
        assertThat("resource.file.alias", newResource(resource.getFile()), hasNoAlias());
        try {
            // Attempt to reference same file, but via NTFS DATA stream (encoded addPath version) 
            Resource alias = base.addPath("testfile::%24DATA");
            if (alias.exists()) {
                // If it exists, it must be an alias
                assertThat("resource.alias", alias, isAliasFor(resource));
                assertThat("resource.uri.alias", newResource(alias.getURI()), isAliasFor(resource));
                assertThat("resource.file.alias", newResource(alias.getFile()), isAliasFor(resource));
            }
        } catch (InvalidPathException e) {
            // NTFS filesystem streams are unsupported on some platforms.
            assumeNoException(e);
        }
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Example 42 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testAddInitialDoubleSlash.

@Test
public void testAddInitialDoubleSlash() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path basePath = dir.resolve("base");
    FS.ensureDirExists(basePath);
    Path filePath = basePath.resolve("foo.txt");
    Files.createFile(filePath);
    try (Resource base = newResource(basePath.toFile())) {
        assertThat("Exists: " + basePath, base.exists(), is(true));
        assertThat("Alias: " + basePath, base, hasNoAlias());
        Resource r = base.addPath("//foo.txt");
        assertThat("getURI()", r.getURI().toASCIIString(), containsString("//foo.txt"));
        assertThat("isAlias()", r.isAlias(), is(true));
        assertThat("getAlias()", r.getAlias(), notNullValue());
        assertThat("getAlias()", r.getAlias().toASCIIString(), containsString("/foo.txt"));
        assertThat("Exists: " + r, r.exists(), is(true));
    } catch (InvalidPathException e) {
    // Exception is acceptable
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Example 43 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testAddPath_WindowsSlash.

@Test
public void testAddPath_WindowsSlash() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path basePath = dir.resolve("base");
    FS.ensureDirExists(basePath);
    Path dirPath = basePath.resolve("aa");
    FS.ensureDirExists(dirPath);
    Path filePath = dirPath.resolve("foo.txt");
    Files.createFile(filePath);
    try (Resource base = newResource(basePath.toFile())) {
        assertThat("Exists: " + basePath, base.exists(), is(true));
        assertThat("Alias: " + basePath, base, hasNoAlias());
        Resource r = base.addPath("aa\\/foo.txt");
        assertThat("getURI()", r.getURI().toASCIIString(), containsString("aa%5C/foo.txt"));
        if (OS.IS_WINDOWS) {
            assertThat("isAlias()", r.isAlias(), is(true));
            assertThat("getAlias()", r.getAlias(), notNullValue());
            assertThat("getAlias()", r.getAlias().toASCIIString(), containsString("aa/foo.txt"));
            assertThat("Exists: " + r, r.exists(), is(true));
        } else {
            assertThat("isAlias()", r.isAlias(), is(false));
            assertThat("Exists: " + r, r.exists(), is(false));
        }
    } catch (InvalidPathException e) {
    // Exception is acceptable
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Example 44 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testExist_BadURINull.

@Test
public void testExist_BadURINull() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path path = dir.resolve("a.jsp");
    Files.createFile(path);
    try {
        // request with null at end
        URI uri = testdir.getPath().toUri().resolve("a.jsp%00");
        assertThat("Null URI", uri, notNullValue());
        Resource r = newResource(uri);
        // if we have r, then it better not exist
        assertFalse(r.exists());
    } catch (InvalidPathException e) {
    // Exception is acceptable
    }
}
Also used : Path(java.nio.file.Path) URI(java.net.URI) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Example 45 with InvalidPathException

use of java.nio.file.InvalidPathException in project buck by facebook.

the class FileClassPathRunner method readUrls.

// @VisibleForTesting
@SuppressWarnings("PMD.EmptyCatchBlock")
static List<URL> readUrls(List<Path> paths, boolean modifySystemClassPathProperty) throws IOException {
    List<URL> readUrls = new LinkedList<>();
    List<String> classPathEntries = new LinkedList<>();
    // format of "file/" to indicate a directory and assuming all other files are jars.
    for (Path path : paths) {
        if (!Files.exists(path)) {
            continue;
        }
        List<String> lines = Files.readAllLines(path, UTF_8);
        for (String line : lines) {
            if (line.isEmpty()) {
                continue;
            }
            try {
                Path entry = Paths.get(line);
                readUrls.add(entry.toUri().toURL());
                classPathEntries.add(entry.toString());
            } catch (InvalidPathException e) {
            // Carry on regardless --- java allows us to put absolute garbage into the classpath.
            }
        }
    }
    String classpathProperty = System.getProperty("java.class.path");
    if (classpathProperty == null) {
        throw new NullPointerException("java.class.path system property must not be null");
    }
    StringBuilder newClassPath = new StringBuilder();
    constructNewClassPath(newClassPath, classpathProperty, classPathEntries);
    if (modifySystemClassPathProperty) {
        System.setProperty("java.class.path", newClassPath.toString());
    }
    return readUrls;
}
Also used : Path(java.nio.file.Path) LinkedList(java.util.LinkedList) URL(java.net.URL) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)97 Path (java.nio.file.Path)53 IOException (java.io.IOException)26 URL (java.net.URL)14 File (java.io.File)13 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 InputStream (java.io.InputStream)4 FileOutStream (alluxio.client.file.FileOutStream)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)2