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:com.splicemachine.storage.HNIOFileSystem.java

@Override
public boolean isSameFile(Path path, Path path2) throws IOException {
    return path.equals(path2);
}

From source file:org.apache.nifi.minifi.bootstrap.configuration.ingestors.FileChangeIngestor.java

protected boolean targetChanged() {
    boolean targetChanged = false;

    final WatchKey watchKey = this.watchService.poll();

    if (watchKey == null) {
        return targetChanged;
    }/*w  w w . j a v  a  2 s .  co  m*/

    for (WatchEvent<?> watchEvt : watchKey.pollEvents()) {
        final WatchEvent.Kind<?> evtKind = watchEvt.kind();

        final WatchEvent<Path> pathEvent = (WatchEvent<Path>) watchEvt;
        final Path changedFile = pathEvent.context();

        // determine target change by verifying if the changed file corresponds to the config file monitored for this path
        targetChanged = (evtKind == ENTRY_MODIFY
                && changedFile.equals(configFilePath.getName(configFilePath.getNameCount() - 1)));
    }

    // After completing inspection, reset for detection of subsequent change events
    boolean valid = watchKey.reset();
    if (!valid) {
        throw new IllegalStateException("Unable to reinitialize file system watcher.");
    }

    return targetChanged;
}

From source file:ch.bender.evacuate.Runner.java

/**
 * preVisitDirectory/*  w w w  .j ava2 s. c o  m*/
 * <p>
 * @param aDir
 * @param aAttrs
 * @return
 * @throws IOException
 */
FileVisitResult preVisitDirectory(Path aDir, BasicFileAttributes aAttrs) throws IOException {
    if (aDir.equals(myBackupDir)) {
        myLog.debug("Visiting the backup root. This directory is never subject of evactuation");
        return FileVisitResult.CONTINUE;
    }

    myLog.debug("Visiting directory " + aDir.toString());
    return visit(aDir);
}

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

/**
 * copies file./*from w  ww  .  j  a  va 2s .c  om*/
 * 
 * @param oldFilename
 *          the old filename
 * @param newFilename
 *          the new filename
 * @return true, when we copied file OR DEST IS EXISTING
 */
private static boolean copyFile(Path oldFilename, Path newFilename) {
    if (!oldFilename.toAbsolutePath().toString().equals(newFilename.toAbsolutePath().toString())) {
        LOGGER.info("copy file " + oldFilename + " to " + newFilename);
        if (oldFilename.equals(newFilename)) {
            // windows: name differs, but File() is the same!!!
            // use move in this case, which handles this
            return moveFile(oldFilename, newFilename);
        }
        try {
            // create parent if needed
            if (!Files.exists(newFilename.getParent())) {
                Files.createDirectory(newFilename.getParent());
            }
            Utils.copyFileSafe(oldFilename, newFilename, true);
            return true;
        } catch (Exception e) {
            return false;
        }
    } else { // file is the same, return true to keep file
        return true;
    }
}

From source file:desktopsearch.WatchDir.java

/**
 * Register the given directory with the WatchService
 *//*from  w  w w.j a v  a  2s . com*/
private void register(Path dir) throws IOException {
    WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
    if (trace) {
        Path prev = keys.get(key);
        if (prev == null) {
            System.out.format("register: %s\n", dir);
        } else if (!dir.equals(prev)) {
            System.out.format("update: %s -> %s\n", prev, dir);
        }
    }
    keys.put(key, dir);
}

From source file:com.garyclayburg.filesystem.WatchDir.java

/**
 * Register the given directory with the WatchService
 *///from  www  .  j av a2s . c o m
private void register(Path dir) throws IOException {
    WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
    if (trace) {
        Path prev = keys.get(key);
        if (prev == null) {
            log.debug("register: {}", dir);
        } else {
            if (!dir.equals(prev)) {
                log.debug("update: {} -> {}", prev, dir);
            }
        }
    }
    keys.put(key, dir);
}

From source file:org.dia.kafka.isatools.producer.DirWatcher.java

/**
 * Register the given directory with the WatchService
 *
 * @param dir to be examine/*from   w w  w  .jav  a 2  s  . c o m*/
 */
private void register(Path dir) throws IOException {
    if (!dir.toFile().isHidden()) {
        WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
        Path prev = keys.get(key);
        if (prev == null) {
            System.out.format("[%s] Registering %s\n", ISAToolsKafkaProducer.class.getSimpleName(), dir);
        } else {
            if (!dir.equals(prev)) {
                System.out.format("[%s] Update %s -> %s\n", ISAToolsKafkaProducer.class.getSimpleName(), prev,
                        dir);
            }
        }
        keys.put(key, dir);
    }
}

From source file:dk.dma.ais.downloader.QueryService.java

/**
 * called every hour to clean up the repo
 *///from   w w w. j  a v  a2  s. c  om
@Scheduled(cron = "12 27 */1 * * *")
public void cleanUpRepoFolder() {

    long now = System.currentTimeMillis();
    long expiredTime = now - FILE_EXPIRY_MS;

    try {
        Files.walkFileTree(getRepoRoot(), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                if (!dir.equals(getRepoRoot()) && isDirEmpty(dir)) {
                    log.info("Deleting repo directory :" + dir);
                    Files.delete(dir);
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (Files.getLastModifiedTime(file).toMillis() < expiredTime) {
                    log.info("Deleting repo file      :" + file);
                    Files.delete(file);
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        log.log(Level.SEVERE, "Failed cleaning up repo: " + e.getMessage());
    }

    log.info(String.format("Cleaned up repo in %d ms", System.currentTimeMillis() - now));
}

From source file:com.aol.advertising.qiao.injector.file.watcher.QiaoFileManager.java

private Path renameFile(Path src, Path target) throws IOException {
    if (!target.equals(src)) {
        logger.info("Rename file from " + src + " to " + target);
        Files.move(src, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
    }/*from www . j  av  a  2s.com*/

    return target;
}

From source file:fr.duminy.jbackup.core.ConfigurationManagerTest.java

@Test
public void testLoadAllConfigurations_wrongXmlConfigFile() throws Exception {
    // prepare mock
    final Path wrongXmlConfigFile = configDir.resolve("wrongXmlConfigFile.xml");
    createFile(wrongXmlConfigFile, "<root></root>");

    ConfigurationManager mock = spy(manager);
    doCallRealMethod().when(mock).loadAllConfigurations();
    final List<Exception> errors = new ArrayList<>();
    doAnswer(new Answer() {
        @Override/*from  w ww .  ja v a 2s.c  o  m*/
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Path file = (Path) invocation.getArguments()[0];
            if (file.equals(wrongXmlConfigFile)) {
                try {
                    return invocation.callRealMethod();
                } catch (Exception e) {
                    errors.add(e);
                    throw e;
                }
            } else {
                return invocation.callRealMethod();
            }
        }
    }).when(mock).loadBackupConfiguration(any(Path.class));

    // test
    LOG.warn("**************************************************************");
    LOG.warn("***** The following logged ERROR is expected by the test *****");
    LOG.warn("**************************************************************");
    mock.loadAllConfigurations();

    // verify
    verify(mock, times(1)).loadBackupConfiguration(eq(wrongXmlConfigFile));
    verify(mock, times(1)).loadAllConfigurations();
    verifyNoMoreInteractions(mock);
    assertThat(errors).as("number of invalid xml files").hasSize(1);
    ConfigurationManagerAssert.assertThat(mock).hasNoBackupConfigurations();
    LOG.warn("**************************************************************");
    LOG.warn("*************** End of expected ERROR in test ***************");
    LOG.warn("**************************************************************");
}