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:org.codebuilder.template.TemplateReader.java

/**
 * How to keep track of all the modified times
 * across the paths.  Note that a file might have
 * appeared in a directory which is earlier in the
 * path; so we should search the path and see if
 * the file we find that way is the same as the one
 * that we have cached.//  w w  w .  j  ava  2s .co m
 */
public boolean isSourceModified(Resource resource) {
    /*
     * we assume that the file needs to be reloaded;
     * if we find the original file and it's unchanged,
     * then we'll flip this.
     */
    boolean modified = true;

    String fileName = resource.getName();
    String path = (String) templatePaths.get(fileName);
    File currentFile = null;

    for (int i = 0; currentFile == null && i < paths.size(); i++) {
        String testPath = (String) paths.get(i);
        File testFile = new File(testPath, fileName);
        if (testFile.canRead()) {
            currentFile = testFile;
        }
    }
    File file = new File(path, fileName);
    if (currentFile == null || !file.exists()) {
        /*
         * noop: if the file is missing now (either the cached
         * file is gone, or the file can no longer be found)
         * then we leave modified alone (it's set to true); a
         * reload attempt will be done, which will either use
         * a new template or fail with an appropriate message
         * about how the file couldn't be found.
         */
    } else if (currentFile.equals(file) && file.canRead()) {
        /*
         * if only if currentFile is the same as file and
         * file.lastModified() is the same as
         * resource.getLastModified(), then we should use the
         * cached version.
         */
        modified = (file.lastModified() != resource.getLastModified());
    }

    /*
     * rsvc.debug("isSourceModified for " + fileName + ": " + modified);
     */
    return modified;
}

From source file:org.apache.james.mailbox.maildir.mail.MaildirMessageMapper.java

/**
 * @see org.apache.james.mailbox.store.mail.MessageMapper#updateFlags(org.apache.james.mailbox.store.mail.model.Mailbox,
 *      javax.mail.Flags, boolean, boolean,
 *      org.apache.james.mailbox.model.MessageRange)
 *///from w  w w .j  a v a  2 s. c  om
@Override
public Iterator<UpdatedFlags> updateFlags(Mailbox mailbox, FlagsUpdateCalculator flagsUpdateCalculator,
        MessageRange set) throws MailboxException {
    final List<UpdatedFlags> updatedFlags = new ArrayList<UpdatedFlags>();
    final MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);

    Iterator<MailboxMessage> it = findInMailbox(mailbox, set, FetchType.Metadata, -1);
    while (it.hasNext()) {
        final MailboxMessage member = it.next();
        Flags originalFlags = member.createFlags();
        member.setFlags(flagsUpdateCalculator.buildNewFlags(originalFlags));
        Flags newFlags = member.createFlags();

        try {
            MaildirMessageName messageName = folder.getMessageNameByUid(mailboxSession, member.getUid());
            if (messageName != null) {
                File messageFile = messageName.getFile();
                // System.out.println("save existing " + message +
                // " as " + messageFile.getName());
                messageName.setFlags(member.createFlags());
                // this automatically moves messages from new to cur if
                // needed
                String newMessageName = messageName.getFullName();

                File newMessageFile;

                // See MAILBOX-57
                if (newFlags.contains(Flag.RECENT)) {
                    // message is recent so save it in the new folder
                    newMessageFile = new File(folder.getNewFolder(), newMessageName);
                } else {
                    newMessageFile = new File(folder.getCurFolder(), newMessageName);
                }
                long modSeq;
                // if the flags don't have change we should not try to move
                // the file
                if (newMessageFile.equals(messageFile) == false) {
                    FileUtils.moveFile(messageFile, newMessageFile);
                    modSeq = newMessageFile.lastModified();

                } else {
                    modSeq = messageFile.lastModified();
                }
                member.setModSeq(modSeq);

                updatedFlags.add(new UpdatedFlags(member.getUid(), modSeq, originalFlags, newFlags));

                long uid = member.getUid();
                folder.update(mailboxSession, uid, newMessageName);
            }
        } catch (IOException e) {
            throw new MailboxException("Failure while save MailboxMessage " + member + " in Mailbox " + mailbox,
                    e);
        }

    }
    return updatedFlags.iterator();

}

From source file:forge.gui.ImportSourceAnalyzer.java

private void analyzeGauntletDataDir(final File root) {
    analyzeDir(root, new Analyzer() {
        @Override/*from ww w . j a  v a  2  s  .  c  o  m*/
        void onFile(final File file) {
            // find *.dat files, but exclude LOCKED_*
            final String filename = file.getName();
            if (StringUtils.endsWithIgnoreCase(filename, ".dat") && !filename.startsWith("LOCKED_")) {
                final File targetFile = new File(ForgeConstants.GAUNTLET_DIR.userPrefLoc, lcaseExt(filename));
                if (!file.equals(targetFile)) {
                    cb.addOp(OpType.GAUNTLET_DATA, file, targetFile);
                }
            }
        }
    });
}

From source file:net.lightbody.bmp.proxy.jetty.util.RolloverFileOutputStream.java

private synchronized void setFile() throws IOException {
    // Check directory
    File file = new File(_filename);
    _filename = file.getCanonicalPath();
    file = new File(_filename);
    File dir = new File(file.getParent());
    if (!dir.isDirectory() || !dir.canWrite())
        throw new IOException("Cannot write log directory " + dir);

    Date now = new Date();

    // Is this a rollover file?
    String filename = file.getName();
    int i = filename.toLowerCase().indexOf(YYYY_MM_DD);
    if (i >= 0) {
        file = new File(dir, filename.substring(0, i) + _fileDateFormat.format(now)
                + filename.substring(i + YYYY_MM_DD.length()));
    }//from w  w w  .ja v  a 2 s  . c o m

    if (file.exists() && !file.canWrite())
        throw new IOException("Cannot write log file " + file);

    // Do we need to change the output stream?
    if (out == null || !file.equals(_file)) {
        // Yep
        _file = file;
        if (!_append && file.exists())
            file.renameTo(new File(file.toString() + "." + _fileBackupFormat.format(now)));
        OutputStream oldOut = out;
        out = new FileOutputStream(file.toString(), _append);
        if (oldOut != null)
            oldOut.close();
        if (log.isDebugEnabled())
            log.debug("Opened " + _file);
    }
}

From source file:de.burlov.amazon.s3.dirsync.DirSync.java

/**
 * Loescht rekursiv leere Verzeichnisse//from   w w w  . j  a v a2s  .  c o  m
 * 
 * @param lowerDir
 *        unterste Verzeichnis, der nicht geloscht werden darf
 * @param dir
 *        Verzeichnis zum loeschen
 */
private void deleteEmptyFolder(final File lowerDir, File dir) {
    if (dir != null && dir.exists() && dir.isDirectory() && !lowerDir.equals(dir)) {
        File[] children = dir.listFiles();
        if (children == null || children.length == 0) {
            dir.delete();
            dir = dir.getParentFile();
            deleteEmptyFolder(lowerDir, dir);
        }
    }
}

From source file:de.blizzy.documentr.page.PageStore.java

private String getParentPagePath(String path, Repository repo) {
    File workingDir = RepositoryUtil.getWorkingDir(repo);
    File pagesDir = new File(workingDir, DocumentrConstants.PAGES_DIR_NAME);
    File pageFile = Util.toFile(pagesDir, path + DocumentrConstants.PAGE_SUFFIX);
    File dir = pageFile.getParentFile();
    StringBuilder buf = new StringBuilder();
    while (!dir.equals(pagesDir)) {
        if (buf.length() > 0) {
            buf.insert(0, '/');
        }//from   w  ww .ja va 2 s. c o  m
        buf.insert(0, dir.getName());
        dir = dir.getParentFile();
    }
    return (buf.length() > 0) ? buf.toString() : null;
}

From source file:org.cloudifysource.usm.launcher.DefaultProcessLauncher.java

private void modifyLinuxCommandLine(final List<String> commandLineParams, final File puWorkDir) {
    String executeScriptName = commandLineParams.get(0);
    final File executeFile = new File(puWorkDir, executeScriptName);
    final File parent = executeFile.getParentFile();
    if (parent != null && parent.equals(puWorkDir)) {
        if (executeScriptName.endsWith(".sh") && !executeScriptName.startsWith(LINUX_EXECUTE_PREFIX)) {
            commandLineParams.remove(0);
            executeScriptName = LINUX_EXECUTE_PREFIX + executeScriptName;
            commandLineParams.add(0, executeScriptName);
        }/*from w  w w  .j  a  v a 2 s .  c om*/
    }

    // LinkedList<String> linkedList =
    // (LinkedList<String>)commandLineParams;
    // linkedList.addAll(0, Arrays.asList("sh", "-c", "\""));

}

From source file:com.google.dart.tools.core.DartCore.java

/**
 * Return <code>true</code> if file is in the dart sdk lib directory
 * //from  w ww.  j a v a 2s . co m
 * @param file
 * @return <code>true</code> if file is in dart-sdk/lib
 */
public static boolean isDartSdkLibraryFile(File file) {
    File sdkLibrary = DartSdkManager.getManager().getSdk().getLibraryDirectory();
    File parentFile = file.getParentFile();
    while (parentFile != null) {
        if (parentFile.equals(sdkLibrary)) {
            return true;
        }
        parentFile = parentFile.getParentFile();
    }
    return false;
}

From source file:forge.gui.ImportSourceAnalyzer.java

private void analyzePreferencesDir(final File root) {
    analyzeDir(root, new Analyzer() {
        @Override/*from   w  w w .  ja v  a2 s .  co m*/
        void onFile(final File file) {
            final String filename = file.getName();
            if ("editor.preferences".equalsIgnoreCase(filename)
                    || "forge.preferences".equalsIgnoreCase(filename)) {
                final File targetFile = new File(ForgeConstants.USER_PREFS_DIR,
                        filename.toLowerCase(Locale.ENGLISH));
                if (!file.equals(targetFile)) {
                    cb.addOp(OpType.PREFERENCE_FILE, file, targetFile);
                }
            }
        }
    });
}

From source file:dalma.container.ClassLoaderImpl.java

/**
 * Indicate if the given file is in this loader's path
 *
 * @param component the file which is to be checked
 *
 * @return true if the file is in the class path
 *//*from  w  w  w.j  a  va 2  s .  c o  m*/
protected boolean isInPath(File component) {
    for (Enumeration e = pathComponents.elements(); e.hasMoreElements();) {
        File pathComponent = (File) e.nextElement();
        if (pathComponent.equals(component)) {
            return true;
        }
    }
    return false;
}