Search in sources :

Example 51 with Path

use of java.nio.file.Path in project crate by crate.

the class FileReadingIterator method getUrisWithGlob.

private List<UriWithGlob> getUrisWithGlob(Collection<String> fileUris) {
    List<UriWithGlob> uris = new ArrayList<>(fileUris.size());
    for (String fileUri : fileUris) {
        URI uri = toURI(fileUri);
        URI preGlobUri = null;
        Predicate<URI> globPredicate = null;
        Matcher hasGlobMatcher = HAS_GLOBS_PATTERN.matcher(uri.toString());
        if (hasGlobMatcher.matches()) {
            if (fileUri.startsWith("/") || fileUri.startsWith("file://")) {
                     * Substitute a symlink with the real path.
                     * The wildcard needs to be maintained, though, because it is used to generate the matcher.
                     * Take the part before the wildcard (*) and try to resolved the real path.
                     * If the part before the wildcard contains a part of the filename (e.g. /tmp/foo_*.json) then use the
                     * parent directory of this filename to resolved the real path.
                     * Then replace this part with the real path and generate the URI.
                Path oldPath = Paths.get(toURI(;
                if (!Files.isDirectory(oldPath)) {
                    oldPath = oldPath.getParent();
                String oldPathAsString;
                String newPathAsString;
                try {
                    oldPathAsString = oldPath.toUri().toString();
                    newPathAsString = oldPath.toRealPath().toUri().toString();
                } catch (IOException e) {
                String resolvedFileUrl = uri.toString().replace(oldPathAsString, newPathAsString);
                uri = toURI(resolvedFileUrl);
                preGlobUri = toURI(newPathAsString);
            } else {
                preGlobUri = URI.create(;
            globPredicate = new GlobPredicate(uri);
        uris.add(new UriWithGlob(uri, preGlobUri, globPredicate));
    return uris;
Also used : Path(java.nio.file.Path) Matcher(java.util.regex.Matcher) IOException( URI(

Example 52 with Path

use of java.nio.file.Path in project cryptomator by cryptomator.

the class MainApplication method handleCommandLineArg.

private void handleCommandLineArg(String arg, Stage primaryStage, MainController mainCtrl) {
    // find correct location:
    final Path path = FileSystems.getDefault().getPath(arg);
    final Path vaultPath;
    if (Files.isDirectory(path)) {
        vaultPath = path;
    } else if (Files.isRegularFile(path)) {
        vaultPath = path.getParent();
    } else {
        LOG.warn("Invalid vault path %s", arg);
    // add vault to ctrl:
    Platform.runLater(() -> {
        mainCtrl.addVault(vaultPath, true);
Also used : Path(java.nio.file.Path)

Example 53 with Path

use of java.nio.file.Path in project crate by crate.

the class AdminUIStaticFileRequestFilter method serveSite.

private void serveSite(RestRequest request, RestChannel channel) throws IOException {
    if (request.method() != RestRequest.Method.GET) {
        channel.sendResponse(new BytesRestResponse(FORBIDDEN));
    String sitePath = StringUtils.stripFront(request.rawPath(), '/');
    // this is a relative path under _site configured by the plugin.
    if (sitePath.length() == 0) {
        sitePath = "index.html";
    final Path siteFile = environment.pluginsFile().resolve("crate-admin").resolve("_site");
    final String separator = siteFile.getFileSystem().getSeparator();
    // Convert file separators.
    sitePath = sitePath.replace("/", separator);
    Path file = siteFile.resolve(sitePath);
    // return not found instead of forbidden to prevent malicious requests to find out if files exist or don't exist
    if (!Files.exists(file) || FileSystemUtils.isHidden(file) || !file.toAbsolutePath().normalize().startsWith(siteFile.toAbsolutePath().normalize())) {
        channel.sendResponse(new BytesRestResponse(NOT_FOUND));
    BasicFileAttributes attributes = readAttributes(file, BasicFileAttributes.class);
    if (!attributes.isRegularFile()) {
        // If it's not a regular file, we send a 403
        channel.sendResponse(new BytesRestResponse(FORBIDDEN));
    try {
        byte[] data = Files.readAllBytes(file);
        channel.sendResponse(new BytesRestResponse(OK, guessMimeType(file.toAbsolutePath().toString()), data));
    } catch (IOException e) {
        channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR));
Also used : Path(java.nio.file.Path) IOException( BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 54 with Path

use of java.nio.file.Path in project che by eclipse.

the class XMLTreeTest method shouldBeAbleToCreateTreeFromPath.

public void shouldBeAbleToCreateTreeFromPath() throws Exception {
    final byte[] bytes = XML_CONTENT.getBytes();
    final Path path = targetDir().resolve("test-xml.xml");
    write(path, bytes);
    final XMLTree tree = XMLTree.from(path);
    assertEquals(tree.getBytes(), bytes);
Also used : Path(java.nio.file.Path) Test(org.testng.annotations.Test)

Example 55 with Path

use of java.nio.file.Path in project che by eclipse.

the class PersistTestModuleBuilderTest method generatesPersistenceXml.

public void generatesPersistenceXml() throws Exception {
    Path path = new PersistTestModuleBuilder().setDriver("org.h2.Driver").addEntityClass(MyEntity1.class).addEntityClass("org.eclipse.che.commons.test.db.PersistTestModuleBuilderTest$MyEntity2").setUrl("jdbc:h2:mem:test").setUser("username").setPassword("secret").setLogLevel("FINE").setPersistenceUnit("test-unit").setExceptionHandler(MyExceptionHandler.class).setProperty("custom-property", "value").savePersistenceXml();
    URL url = Thread.currentThread().getContextClassLoader().getResource("org/eclipse/che/commons/test/db/test-persistence-1.xml");
    assertEquals(new String(Files.readAllBytes(path), UTF_8), Resources.toString(url, UTF_8));
Also used : Path(java.nio.file.Path) URL( Test(org.testng.annotations.Test)


Path (java.nio.file.Path)4893 Test (org.junit.Test)1960 IOException ( File ( SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem ( BuildTarget (com.facebook.buck.model.BuildTarget)320 ArrayList (java.util.ArrayList)313 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 InputStream ( ImmutableList ( FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 HashMap (java.util.HashMap)159 ImmutableMap ( SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)154 Matchers.containsString (org.hamcrest.Matchers.containsString)148 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)147 Map (java.util.Map)146