Example usage for java.io File equals

List of usage examples for java.io File equals

Introduction

In this page you can find the example usage for java.io File equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Tests this abstract pathname for equality with the given object.

Usage

From source file:net.doubledoordev.backend.server.FileManager.java

public String stripServer(File file) {
    if (file.equals(serverFolder))
        return serverFolder.getName();
    return file.toString().substring(serverFolder.toString().length() + 1).replace('\\', '/');
}

From source file:deployer.publishers.openshift.RhcApplicationGitRepoModificationsTest.java

private void assertGitRepositoryFilesForUpdateGitRepoTest(final File testDir) throws IOException {
    final File gitDbDir = Files.resolve(testDir, ".git");
    final File AppJar = Files.get("bin", "myApplication.jar");
    final File AppConf = Files.get(TestUtils.CONFIG_DIRECTORY, "app.conf");
    final File extraInfo = Files.get(TestUtils.CONFIG_DIRECTORY, "extraInfo.conf");
    final File versionFile = Files.get("deployed_version.txt");

    final Set<File> expectedFiles = Sets.newHashSet(AppJar, AppConf, extraInfo, versionFile);
    final Set<File> foundUnexpectedFiles = Sets.newHashSet();
    Files.walkFileTree(testDir, new FileVisitor<File>() {
        @Override/* w w  w  .  j av  a2s .com*/
        public FileVisitResult preVisitDirectory(File dir, BasicFileAttributes attrs) throws IOException {
            if (dir.equals(gitDbDir))
                return FileVisitResult.SKIP_SUBTREE;
            else
                return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(File file, BasicFileAttributes attrs) throws IOException {
            File relFile = Files.relativize(testDir, file);
            if (!expectedFiles.contains(relFile)) {
                foundUnexpectedFiles.add(relFile);
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(File file, IOException exc) throws IOException {
            System.out.println("visitFileFailed(" + file + ")");
            return FileVisitResult.CONTINUE;

        }

        @Override
        public FileVisitResult postVisitDirectory(File dir, IOException exc) throws IOException {
            if (dir.equals(gitDbDir))
                return FileVisitResult.SKIP_SUBTREE;
            else
                return FileVisitResult.CONTINUE;
        }
    });
    assertTrue("Unexpected files remains in gitRepo: " + Joiner.on(",").join(foundUnexpectedFiles),
            foundUnexpectedFiles.isEmpty());

    assertEquals("This is not really a jar for the sake of easiness of test",
            FileUtils.readFileToString(Files.resolve(testDir, AppJar)));
    assertEquals("sample.key=sample value\nsample.pass=blah blah",
            FileUtils.readFileToString(Files.resolve(testDir, AppConf)));
    assertEquals("Extra information", FileUtils.readFileToString(Files.resolve(testDir, extraInfo)));
    assertEquals("v1.0", FileUtils.readFileToString(Files.resolve(testDir, versionFile)));
}

From source file:com.docdoku.server.storage.filesystem.FileStorageProvider.java

private void cleanRemove(File pFile) {
    if (!pFile.equals(new File(vaultPath)) && pFile.delete())
        cleanRemove(pFile.getParentFile());
}

From source file:org.commonjava.maven.ext.manip.CliTest.java

@Test
public void checkTargetMatchesWithRun() throws Exception {
    Cli c = new Cli();
    File pom1 = new File("/tmp/foobar");

    executeMethod(c, "run", new Object[] { new String[] { "-f", pom1.toString() } });

    assertTrue("Session file should match",
            pom1.equals(((ManipulationSession) FieldUtils.readField(c, "session", true)).getPom()));
}

From source file:org.apache.druid.segment.loading.SegmentLoaderLocalCacheManager.java

private void cleanupCacheFiles(File baseFile, File cacheFile) {
    if (cacheFile.equals(baseFile)) {
        return;// w  w w . j a va2s  .  co  m
    }

    synchronized (lock) {
        log.info("Deleting directory[%s]", cacheFile);
        try {
            FileUtils.deleteDirectory(cacheFile);
        } catch (Exception e) {
            log.error("Unable to remove file[%s]", cacheFile);
        }
    }

    File parent = cacheFile.getParentFile();
    if (parent != null) {
        File[] children = parent.listFiles();
        if (children == null || children.length == 0) {
            cleanupCacheFiles(baseFile, parent);
        }
    }
}

From source file:org.opoo.press.impl.SiteObserver.java

/**
 * Create configuration files FileFilter.
 * @return file filter/*w  w w.  j  av a2 s .c om*/
 */
private FileFilter createConfigFilesFilter() {
    Config config = site.getConfig();
    boolean useDefaultConfigFiles = config.useDefaultConfigFiles();
    if (useDefaultConfigFiles) {
        log.debug("Using default config files.");
        return ConfigImpl.DEFAULT_CONFIG_FILES_FILTER;
    } else {//custom config files
        final File[] configFiles = config.getConfigFiles();
        return new FileFilter() {
            @Override
            public boolean accept(File file) {
                for (File configFile : configFiles) {
                    if (configFile.equals(file)) {
                        return true;
                    }
                }
                return false;
            }
        };
    }
}

From source file:com.amazonaws.eclipse.elasticbeanstalk.git.AWSGitPushCommand.java

private void clearOutRepository(Repository repository) throws IOException {
    // Delete all the old files before copying the new files
    final File gitMetadataDirectory = repository.getIndexFile().getParentFile();

    FileFilter fileFilter = new FileFilter() {
        public boolean accept(final File file) {
            if (file.equals(gitMetadataDirectory))
                return false;
            if (!file.getParentFile().equals(repoLocation))
                return false;
            return true;
        }/*  w w w  .ja  v  a 2 s  .com*/
    };

    for (File f : repoLocation.listFiles(fileFilter)) {
        FileUtils.delete(f, FileUtils.RECURSIVE);
    }
}

From source file:net.doubledoordev.backend.server.FileManager.java

public Collection<File> makeBreadcrumbs() {
    LinkedList<File> list = new LinkedList<>();

    File crumb = file;
    while (!crumb.equals(serverFolder)) {
        list.add(crumb);//from ww  w  .j a  va2s  .  c o  m
        crumb = crumb.getParentFile();
    }

    list.add(serverFolder);

    Collections.reverse(list);
    return list;
}

From source file:Main.java

/**
 * Checks, whether the child directory is a subdirectory of the base 
 * directory.//from  w w  w  . j av  a2 s .c  om
 *
 * @param base the base directory.
 * @param child the suspected child directory.
 * @return true, if the child is a subdirectory of the base directory.
 * @throws IOException if an IOError occured during the test.
 */
public boolean isSubDirectory(File base, File child) throws IOException {
    base = base.getCanonicalFile();
    child = child.getCanonicalFile();

    File parentFile = child;
    while (parentFile != null) {
        if (base.equals(parentFile)) {
            return true;
        }
        parentFile = parentFile.getParentFile();
    }
    return false;
}

From source file:org.path.common.android.utilities.ODKFileUtils.java

public static String extractAppNameFromPath(File path) {

    if (path == null) {
        return null;
    }/* w  w  w  .j  a  va  2s .com*/

    File parent = path.getParentFile();
    File odkDir = new File(getEpiSampleFolder());
    while (parent != null && !parent.equals(odkDir)) {
        path = parent;
        parent = path.getParentFile();
    }

    if (parent == null) {
        return null;
    } else {
        return path.getName();
    }
}