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:es.uvigo.ei.sing.adops.datatypes.ProjectExperiment.java

@Override
public void clear() {
    final FileFilter filter = new FileFilter() {
        @Override/*from   w w w .  j  a  va2  s  .c o m*/
        public boolean accept(File pathname) {
            if (pathname.equals(ProjectExperiment.this.getNotesFile())
                    || pathname.equals(ProjectExperiment.this.getPropertiesFile())
                    || pathname.equals(ProjectExperiment.this.getFastaFile())
                    || pathname.equals(ProjectExperiment.this.getNamesFile())
                    || pathname.equals(ProjectExperiment.this.getFilesFolder())) {
                return false;
            }

            return true;
        }
    };

    for (File file : this.getFolder().listFiles(filter)) {
        if (file.isFile())
            file.delete();
        else if (file.isDirectory())
            try {
                FileUtils.deleteDirectory(file);
            } catch (IOException e) {
            }
    }

    try {
        FileUtils.cleanDirectory(this.getFilesFolder());
    } catch (IOException e) {
    }

    new File(this.getFilesFolder(), TCoffeeOutput.OUTPUT_FOLDER_NAME).mkdirs();
    new File(this.getFilesFolder(), MrBayesOutput.OUTPUT_FOLDER_NAME).mkdirs();
    new File(this.getFilesFolder(), CodeMLOutput.OUTPUT_FOLDER_NAME).mkdirs();

    this.result = null;

    this.setChanged();
    this.notifyObservers();
}

From source file:ezbake.deployer.publishers.openShift.RhcApplication.java

/**
 * Calls delete on every file in this application directory.  (basically git rm -r .)  This should allow for only
 * new files to be seen in the project directory.  This is automatically called by @{link #updateWithTarBall}, this
 * is here to allow a more flexible updating of the project if needed.
 *
 * @throws DeploymentException - on any git error while removing.
 */// www.  j  a va2 s  .c o  m
public void clearProjectDirectory() throws DeploymentException {

    final File gitDbPath = gitRepo.getRepository().getDirectory();
    final File gitRepoPath = gitDbPath.getParentFile();
    try {

        Files.walkFileTree(gitRepoPath, new SimpleFileVisitor<File>() {
            public FileVisitResult visitFile(File file, BasicFileAttributes attrs) throws IOException {
                File rel = Files.relativize(gitRepoPath, file);
                try {
                    gitRepo.rm().addFilepattern(rel.toString()).call();
                } catch (GitAPIException e) {
                    throw new IOException(e);
                }
                return FileVisitResult.CONTINUE;
            }

            public FileVisitResult visitFileFailed(File file, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            public FileVisitResult postVisitDirectory(File dir, IOException exc) throws IOException {
                //println("postVisitDirectory(${dir})");
                if (exc == null) {
                    if (dir.equals(gitDbPath))
                        return FileVisitResult.SKIP_SUBTREE;
                    return FileVisitResult.CONTINUE;
                } else {
                    // directory iteration failed; propagate exception
                    throw exc;
                }
            }

            public FileVisitResult preVisitDirectory(File dir, BasicFileAttributes attrs) throws IOException {
                //println("preVisitDirectory(${dir})");
                if (dir.equals(gitDbPath))
                    return FileVisitResult.SKIP_SUBTREE;
                else
                    return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        log.error("[" + getApplicationName() + "]Error cleaning out directory: " + gitRepoPath.toString(), e);
        throw new DeploymentException(e.getMessage());
    }
}

From source file:net.pandoragames.far.ui.FARConfig.java

/**
 * Loads the base and the backupd directory from a Properties object.
 * The property names are defined as constants of this class.
 * The property values are supposed to be valid pathes, but both
 * directories are controlled for existance. Inheriting classes may overwrite
 * this method to load additional properties.
 * @param properties holding properties for base and backup directory.
 *//*from w w w.  j ava 2 s.c o  m*/
protected void loadFromProperties(Properties properties) {
    // base directory
    File baseDir = getValidDirectory(properties.getProperty(PPT_BASEDIR));
    if (baseDir != null) {
        setBaseDirectory(baseDir);
    } else {
        logger.info("Base directory " + properties.getProperty(PPT_BASEDIR)
                + " could not be restored. Using fall back: " + lastBaseDir.getPath());
    }
    // backup directory
    File bckpDir = getValidDirectory(properties.getProperty(PPT_BCKPDIR));
    if (bckpDir != null) {
        if (bckpDir.canWrite()) {
            if (bckpDir.equals(new File(System.getProperty("java.io.tmpdir")))) {
                bckpDir = makeDefaultBackupDir();
            }
            setBackupDirectory(bckpDir);
        } else {
            defaultBackupDirectory = makeDefaultBackupDir();
            logger.info("Backup directory " + properties.getProperty(PPT_BCKPDIR)
                    + " is not writable. Using fall back: " + defaultBackupDirectory.getPath());
        }
    } else {
        defaultBackupDirectory = makeDefaultBackupDir();
        if (!defaultBackupDirectory.getPath().equals(properties.getProperty(PPT_BCKPDIR))) {
            logger.info("Backup directory " + properties.getProperty(PPT_BCKPDIR)
                    + " could not be restored. Using fall back: " + defaultBackupDirectory.getPath());
        }
    }
    // list impex directory
    setFileListExportDirectory(getValidDirectory(properties.getProperty(PPT_LISTEXDIR)));
    // group reference indicator
    String grefind = properties.getProperty(PPT_GROUPREF);
    if (grefind == null || !(grefind.equals(GROUPREFINDICATORLIST[0])
            || grefind.equals(GROUPREFINDICATORLIST[1]) || grefind.equals(GROUPREFINDICATORLIST[2]))) {
        grefind = GROUPREFINDICATORLIST[0];
    }
    groupReferenceIndicator = grefind.charAt(0);
    // application version
    String versionNumber = properties.getProperty(PPT_VERSION);
    String currentVersion = getCurrentApplicationVersion();
    if (currentVersion != null && !currentVersion.equals(versionNumber)) {
        versionHasChanged = true;
    }
    processBinary = Boolean.parseBoolean(properties.getProperty(PPT_BINARY));
    if (properties.containsKey(PPT_UNKNOWN_AS_BINARY)) {
        FileType.TREAT_UNKNOWN_AS_BINARY = Boolean.parseBoolean(properties.getProperty(PPT_UNKNOWN_AS_BINARY));
    }
}

From source file:org.mule.module.launcher.log4j2.LoggerContextConfigurer.java

private boolean isUrlInsideDirectory(URI uri, File directory) {
    if (uri == null) {
        return false;
    }// w w  w  .j ava2s.  c  om

    URL url;
    try {
        url = uri.toURL();
    } catch (MalformedURLException e) {
        throw new MuleRuntimeException(MessageFactory.createStaticMessage("Could not locate file " + uri), e);
    }

    if (directory != null && FileUtils.isFile(url)) {
        File urlFile = new File(url.getFile());
        return directory.equals(urlFile.getParentFile());
    }

    return false;
}

From source file:net.sf.jabref.external.DroppedFileHandler.java

/**
 * Copy the given file to the base directory for its file type, and give it
 * the given name./*from  ww w  . ja  va2s.  c om*/
 *
 * @param fileName The name of the source file.
 * @param toFile   The destination filename. An existing path-component will be removed.
 * @param edits    TODO we should be able to undo this!
 * @return
 */
private boolean doCopy(String fileName, String toFile, NamedCompound edits) {

    List<String> dirs = panel.getBibDatabaseContext().getFileDirectory();
    int found = -1;
    for (int i = 0; i < dirs.size(); i++) {
        if (new File(dirs.get(i)).exists()) {
            found = i;
            break;
        }
    }
    if (found < 0) {
        // OOps, we don't know which directory to put it in, or the given
        // dir doesn't exist....
        // This should not happen!!
        LOGGER.warn("Cannot determine destination directory or destination directory does not exist");
        return false;
    }
    String destinationFileName = new File(toFile).getName();

    File destFile = new File(dirs.get(found) + System.getProperty("file.separator") + destinationFileName);
    if (destFile.equals(new File(fileName))) {
        // File is already in the correct position. Don't override!
        return true;
    }

    if (destFile.exists()) {
        int answer = JOptionPane.showConfirmDialog(frame,
                Localization.lang("'%0' exists. Overwrite file?", destFile.getPath()),
                Localization.lang("File exists"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (answer == JOptionPane.NO_OPTION) {
            return false;
        }
    }
    try {
        FileUtil.copyFile(new File(fileName), destFile, true);
    } catch (IOException e) {
        LOGGER.error("Problem copying file", e);
        return false;
    }

    return true;
}

From source file:com.github.riccardove.easyjasub.EasyJaSubInputFromCommand.java

private static File getTranslatedSubFile(EasyJaSubInputCommand command, Iterable<File> defaultFileList,
        File japaneseSubFile, SubtitleFileType japaneseSubFileType) throws EasyJaSubException {
    String fileName = command.getTranslatedSubFileName();
    if (isDisabled(fileName)) {
        return null;
    }/*  w w w  . j a  v  a2 s  .  c  o  m*/
    if (fileName != null && !isDefault(fileName)) {
        File file = new File(fileName);
        checkFile(fileName, file);
        if (!isTextContentType(file)) {
            throw new EasyJaSubException(
                    "File " + fileName + " does not seem to be text, type is " + probeContentType(file));
        }
        if (!isSubExtension(getExtension(file))) {
            throw new EasyJaSubException("File " + fileName + " does not have a valid subtitle file extension");
        }
        return file;
    }
    if (japaneseSubFileType != SubtitleFileType.TXT) {
        // by default, no translation when japanese is in text format
        for (File file : defaultFileList) {
            String extension = getExtension(file);
            if (!file.equals(japaneseSubFile) && isTextContentType(file) && isSubExtension(extension)) {
                return file;
            }
        }
    }
    return null;
}

From source file:net.testdriven.psiprobe.beans.LogResolverBean.java

public List<LogDestination> getLogSources(File logFile) {
    List<LogDestination> filtered = new LinkedList<>();
    List<LogDestination> sources = getLogSources();
    for (Object source : sources) {
        LogDestination dest = (LogDestination) source;
        if (logFile.equals(dest.getFile())) {
            filtered.add(dest);/*w w w . jav  a2s  .c  o m*/
        }
    }
    return filtered;
}

From source file:org.apache.jmeter.services.FileServer.java

/**
 * Calculates the relative path from {@link #DEFAULT_BASE} to the current base,
 * which must be the same as or a child of the default.
 * //w  w  w.j a v  a2  s .  c om
 * @return the relative path, or {@code "."} if the path cannot be determined
 */
public synchronized File getBaseDirRelative() {
    // Must first convert to absolute path names to ensure parents are available
    File parent = new File(DEFAULT_BASE).getAbsoluteFile();
    File f = base.getAbsoluteFile();
    ArrayStack l = new ArrayStack();
    while (f != null) {
        if (f.equals(parent)) {
            if (l.isEmpty()) {
                break;
            }
            File rel = new File((String) l.pop());
            while (!l.isEmpty()) {
                rel = new File(rel, (String) l.pop());
            }
            return rel;
        }
        l.push(f.getName());
        f = f.getParentFile();
    }
    return new File(".");
}

From source file:com.googlecode.psiprobe.beans.LogResolverBean.java

public List getLogSources(File logFile) {
    List filtered = new LinkedList();
    List sources = getLogSources();
    for (int i = 0; i < sources.size(); i++) {
        LogDestination dest = (LogDestination) sources.get(i);
        if (logFile.equals(dest.getFile())) {
            filtered.add(dest);/*  ww  w . j  a v  a2s  . c o  m*/
        }
    }
    return filtered;
}

From source file:com.frostwire.platform.FileSystemWalkTest.java

@Test
public void testDir() throws IOException {
    File f1 = File.createTempFile("aaa", null);
    File d1 = f1.getParentFile();
    final File d2 = new File(d1, "d2");
    if (d2.exists()) {
        FileUtils.deleteDirectory(d2);//from  w  w  w.  j  av a2s. co m
    }
    assertTrue(d2.mkdir());
    File f2 = new File(d2, "bbb");
    assertTrue(f2.createNewFile());

    final LinkedList<File> l = new LinkedList<>();

    fs.walk(d1, new FileFilter() {
        @Override
        public boolean accept(File file) {
            return true;
        }

        @Override
        public void file(File file) {
            l.add(file);
        }
    });

    Set<File> set = new LinkedHashSet<>(l);
    assertEquals(set.size(), l.size());

    assertFalse(l.contains(d1));
    assertTrue(l.contains(f1));
    assertTrue(l.contains(d2));
    assertTrue(l.contains(f2));

    l.clear();
    fs.walk(d1, new FileFilter() {
        @Override
        public boolean accept(File file) {
            return !file.equals(d2);
        }

        @Override
        public void file(File file) {
            l.add(file);
        }
    });

    assertFalse(l.contains(d1));
    assertTrue(l.contains(f1));
    assertFalse(l.contains(d2));
    assertFalse(l.contains(f2));

    assertTrue(f2.delete());
    assertTrue(d2.delete());
    assertTrue(f1.delete());
}