Example usage for java.nio.file Path equals

List of usage examples for java.nio.file Path equals

Introduction

In this page you can find the example usage for java.nio.file Path equals.

Prototype

boolean equals(Object other);

Source Link

Document

Tests this path for equality with the given object.

Usage

From source file:org.fao.geonet.api.records.formatters.AbstractFormatService.java

protected static boolean containsFile(Path container, Path desiredFile) throws IOException {
    if (!Files.exists(desiredFile) || !Files.exists(container)) {
        return false;
    }//ww w.  ja v  a 2 s . c o  m

    Path canonicalDesired = desiredFile.toRealPath();
    final Path canonicalContainer = container.toRealPath();
    while (canonicalDesired.getParent() != null && !canonicalDesired.getParent().equals(canonicalContainer)) {
        canonicalDesired = canonicalDesired.getParent();
    }

    return canonicalContainer.equals(canonicalDesired.getParent());
}

From source file:org.tinymediamanager.core.movie.MovieRenamerPreview.java

public static MovieRenamerPreviewContainer renameMovie(Movie movie) {
    MovieRenamerPreviewContainer container = new MovieRenamerPreviewContainer(movie);

    LinkedHashMap<String, MediaFile> oldFiles = new LinkedHashMap<>();
    Set<MediaFile> newFiles = new LinkedHashSet<>();

    String newVideoBasename = "";
    if (MovieModuleManager.MOVIE_SETTINGS.getMovieRenamerFilename().trim().isEmpty()) {
        // we are NOT renaming any files, so we keep the same name on renaming ;)
        newVideoBasename = movie.getVideoBasenameWithoutStacking();
    } else {//from ww w .  j a va2  s  .  com
        // since we rename, generate the new basename
        MediaFile ftr = MovieRenamer
                .generateFilename(movie, movie.getMediaFiles(MediaFileType.VIDEO).get(0), newVideoBasename)
                .get(0);
        newVideoBasename = FilenameUtils.getBaseName(ftr.getFilenameWithoutStacking());
    }

    // VIDEO needs to be renamed first, since all others depend on that name!!!
    for (MediaFile mf : movie.getMediaFiles(MediaFileType.VIDEO)) {
        oldFiles.put(mf.getFileAsPath().toString(), new MediaFile(mf));
        MediaFile ftr = MovieRenamer.generateFilename(movie, mf, newVideoBasename).get(0); // there can be only one
        newFiles.add(ftr);
    }

    // all the other MFs...
    for (MediaFile mf : movie.getMediaFilesExceptType(MediaFileType.VIDEO)) {
        oldFiles.put(mf.getFileAsPath().toString(), new MediaFile(mf));
        newFiles.addAll(MovieRenamer.generateFilename(movie, mf, newVideoBasename)); // N:M
    }

    // movie folder needs a rename?
    Path oldMovieFolder = movie.getPathNIO();
    String pattern = MovieModuleManager.MOVIE_SETTINGS.getMovieRenamerPathname();
    if (pattern.isEmpty()) {
        // same
        container.newPath = Paths.get(movie.getDataSource()).relativize(movie.getPathNIO());
    } else {
        container.newPath = Paths.get(MovieRenamer.createDestinationForFoldername(pattern, movie));
    }
    Path newMovieFolder = Paths.get(movie.getDataSource()).resolve(container.newPath);

    if (!oldMovieFolder.equals(newMovieFolder)) {
        container.needsRename = true;
        // update already the "old" files with new path, so we can simply do a contains check ;)
        for (MediaFile omf : oldFiles.values()) {
            omf.replacePathForRenamedFolder(oldMovieFolder, newMovieFolder);
        }
    }

    // change status of MFs, if they have been added or not
    for (MediaFile mf : newFiles) {
        if (!oldFiles.containsKey(mf.getFileAsPath().toString())) {
            // System.out.println(mf);
            container.needsRename = true;
            break;
        }
    }

    for (MediaFile mf : oldFiles.values()) {
        if (!newFiles.contains(mf)) {
            // System.out.println(mf);
            container.needsRename = true;
            break;
        }
    }

    container.newMediaFiles.addAll(newFiles);
    return container;
}

From source file:org.apache.taverna.databundle.DataBundles.java

private static void checkExistingAnyExtension(Path path) throws IOException, FileAlreadyExistsException {
    Path existing = anyExtension(path);
    if (!path.equals(existing))
        throw new FileAlreadyExistsException(existing.toString());
}

From source file:org.roda.core.storage.fs.FSUtils.java

public static void deleteEmptyAncestorsQuietly(Path binVersionPath, Path upToParent) {
    if (binVersionPath == null) {
        return;//from   ww  w  .j  av  a2 s . c  o  m
    }

    Path parent = binVersionPath.getParent();
    while (parent != null && !parent.equals(upToParent)) {
        try {
            Files.deleteIfExists(parent);
            parent = parent.getParent();
        } catch (DirectoryNotEmptyException e) {
            // cancel clean-up
            parent = null;
        } catch (IOException e) {
            LOGGER.warn("Could not cleanup binary version directories", e);
        }
    }
}

From source file:Search.java

void search(Path file) throws IOException {
    Path name = file.getFileName();
    if (name != null && name.equals(searchedFile)) {
        System.out.println("Searched file was found: " + searchedFile + " in " + file.toRealPath().toString());
        found = true;//from   w w w . j  av  a 2  s .  com
    }
}

From source file:com.curecomp.primefaces.migrator.PrimefacesMigration.java

private static void findWidgetVarUsages(Path sourceFile, WidgetVarLocation widgetVarLocation,
        BlockingQueue<WidgetVarLocation> foundUsages, BlockingQueue<WidgetVarLocation> skippedUsages,
        BlockingQueue<WidgetVarLocation> unusedOrAmbiguous) throws IOException {
    try (BufferedReader br = Files.newBufferedReader(sourceFile, StandardCharsets.UTF_8)) {
        int lineNr = 0;
        String line;//  www  . j a  v  a  2  s  .  c o  m
        while ((line = br.readLine()) != null) {
            lineNr++;

            int startIndex = 0;
            int endIndex = -1;

            while ((startIndex = line.indexOf(widgetVarLocation.widgetVar, endIndex + 1)) > -1) {
                endIndex = startIndex + widgetVarLocation.widgetVar.length();

                if (sourceFile.equals(widgetVarLocation.location) && lineNr == widgetVarLocation.lineNr
                        && startIndex == widgetVarLocation.columnNr) {
                    continue;
                }

                WidgetVarLocation usage = new WidgetVarLocation(widgetVarLocation.widgetVar, sourceFile, lineNr,
                        startIndex, line);

                // Only look at lines that use the word as a whole and not just as a part
                if ((startIndex == 0 || !Character.isJavaIdentifierStart(line.charAt(startIndex - 1)))
                        && (line.length() == endIndex
                                || !Character.isJavaIdentifierPart(line.charAt(endIndex)))) {
                    // We skip usages that occur as the last word of a line or usages that don't call methods directly
                    if (endIndex == line.length() || endIndex < line.length() && line.charAt(endIndex) != '.') {
                        skippedUsages.add(usage);
                    } else {
                        foundUsages.add(usage);
                    }
                } else {
                    skippedUsages.add(usage);
                }

                unusedOrAmbiguous.remove(widgetVarLocation);
            }
        }
    }
}

From source file:org.gradle.caching.internal.tasks.FileWalkingBenchmark.java

@Benchmark
public void java7walk(Blackhole blackhole) {
    Path path = missing ? missingPath : existingPath;
    while (!path.equals(tempDirPath)) {
        path = path.getParent();//from   w  w w .j  a va 2  s .c  o  m
        blackhole.consume(Files.exists(path));
    }
    blackhole.consume(path);
}

From source file:bjerne.gallery.service.impl.GalleryRootDirConfigJob.java

private void watchForChanges() {
    Path dir = configFile.getParentFile().toPath();
    try {/*from   w  ww. j  av a2 s  .co  m*/
        WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
        for (;;) {
            try {
                key = watcher.take();
            } catch (InterruptedException | ClosedWatchServiceException e) {
                LOG.info("Interrupted during watcher.take(). Exiting watch loop.");
                return;
            }
            for (WatchEvent<?> event : key.pollEvents()) {
                WatchEvent.Kind<?> kind = event.kind();
                if (kind == OVERFLOW) {
                    continue;
                }

                @SuppressWarnings("unchecked")
                WatchEvent<Path> ev = (WatchEvent<Path>) event;
                Path filename = ev.context();

                Path child = dir.resolve(filename);
                if (child.equals(configFile.toPath())) {
                    LOG.debug("File was changed.");
                    updateConfigFromFile();
                }
            }
            boolean valid = key.reset();
            if (!valid) {
                break;
            }
        }
    } catch (IOException ioe) {
        LOG.error("Exception in filewatcher loop. Exiting.", ioe);
    }
}

From source file:com.ttech.cordovabuild.domain.application.source.ApplicationSourceFactoryImpl.java

private boolean isSubPath(Path path, Path parent) {
    if (path == null)
        return false;
    if (path.equals(parent))
        return true;
    else/*from w  w w .  j av  a2  s. co m*/
        return isSubPath(path.getParent(), parent);
}

From source file:org.wurtele.ifttt.watchers.TrainingScheduleWatcher.java

@Override
public void handleDelete(Path path) {
    try {/* ww w  .ja va 2  s.  c om*/
        if (Files.exists(processedPath(path)) && !path.equals(processedPath(path))) {
            Files.delete(processedPath(path));
            TRAINING_SCHEDULES.remove(processedPath(path));
        }
    } catch (IOException e) {
        logger.error("Failed to remove old training schedule data: " + processedPath(path), e);
    }
}