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:eu.qualimaster.coordination.ProfileControl.java

/**
 * Releases the given <code>instance</code>, i.e., removes it from {@link #INSTANCES}.
 * Unregisters also the name mapping. Deletes temporary files from {@link #data}.
 * /*  ww  w . j  a  va 2s. c  o  m*/
 * @param instance the instance to release
 */
public static void releaseInstance(ProfileControl instance) {
    if (null != instance) {
        File tmp = FileUtils.getTempDirectory();
        File iter = instance.data.getPipeline();
        File parent;
        do {
            parent = iter.getParentFile();
            if (null != parent) {
                if (parent.equals(tmp)) {
                    if (CoordinationConfiguration.deleteProfilingPipelines()) {
                        org.apache.commons.io.FileUtils.deleteQuietly(iter);
                    }
                    break;
                } else {
                    iter = parent;
                }
            }
        } while (null != parent);
        if (null != instance.mapping) {
            CoordinationManager.unregisterNameMapping(instance.mapping);
        }
        INSTANCES.remove(instance.data.getPipelineName());
    }
}

From source file:org.fusesource.meshkeeper.classloader.basic.BasicClassLoaderServer.java

private static void addExportedFile(ArrayList<ExportedFile> elements, File file) throws IOException {
    ExportedFile exportedFile = new ExportedFile();
    exportedFile.file = file;/*  w  ww .ja  va2 s. c om*/

    // No need to add if it does not exist.
    if (!file.exists()) {
        return;
    }
    // No need to add if it's in the list allready..
    for (ExportedFile element : elements) {
        if (file.equals(element.file)) {
            if (LOG.isDebugEnabled())
                LOG.debug("duplicate file :" + file + " on classpath");
            return;
        }
    }

    ArrayList<URL> manifestClasspath = null;

    // if it's a directory, then jar it up..
    if (file.isDirectory()) {
        if (file.list().length <= 0) {
            return;
        }
        if (LOG.isDebugEnabled())
            LOG.debug("Jaring: " + file);
        File jar = exportedFile.jared = jar(file);
        if (LOG.isDebugEnabled())
            LOG.debug("Jared: " + file + " as: " + jar);
        file = jar;
    } else {
        // if it's a file then it needs to be eaither a zip or jar file.
        String name = file.getName();
        if (!(name.endsWith(".jar") || name.endsWith(".zip"))) {
            if (LOG.isDebugEnabled())
                LOG.debug("Not a jar.. ommititng from the classpath: " + file);
            return;
        }

        //Parse the manifest, and include entries in the exported
        //classpath:
        try {
            JarFile jar = new JarFile(file);
            Manifest manifest = jar.getManifest();
            if (manifest != null) {
                String classpath = (String) manifest.getMainAttributes()
                        .get(java.util.jar.Attributes.Name.CLASS_PATH);
                if (classpath != null) {
                    String[] entries = classpath.split(" ");
                    manifestClasspath = new ArrayList<URL>(entries.length);
                    for (String entry : classpath.split(" ")) {
                        manifestClasspath.add(new URL(file.getParentFile().toURI().toURL(), entry));
                    }
                }
            }
        } catch (Exception e) {
            LOG.warn("Error reading jar manifest for: " + file);
        }

    }

    exportedFile.element.id = ids.incrementAndGet();
    exportedFile.element.length = file.length();
    exportedFile.element.fingerprint = BasicClassLoaderFactory.fingerprint(new FileInputStream(file));
    elements.add(exportedFile);

    //Add in any manifest entries:
    if (manifestClasspath != null) {
        addExportedURLs(manifestClasspath.toArray(new URL[] {}), elements);
    }
}

From source file:cd.education.data.collector.android.utilities.EncryptionUtils.java

private static List<File> encryptSubmissionFiles(File instanceXml, File submissionXml,
        EncryptedFormInformation formInfo) throws IOException, EncryptionException {
    // NOTE: assume the directory containing the instanceXml contains ONLY
    // files related to this one instance.
    File instanceDir = instanceXml.getParentFile();

    // encrypt files that do not end with ".enc", and do not start with ".";
    // ignore directories
    File[] allFiles = instanceDir.listFiles();
    List<File> filesToProcess = new ArrayList<File>();
    for (File f : allFiles) {
        if (f.equals(instanceXml))
            continue; // don't touch restore file
        if (f.equals(submissionXml))
            continue; // handled last
        if (f.isDirectory())
            continue; // don't handle directories
        if (f.getName().startsWith("."))
            continue; // MacOSX garbage
        if (f.getName().endsWith(".enc")) {
            f.delete(); // try to delete this (leftover junk)
        } else {//  w w w  . j ava2  s. com
            filesToProcess.add(f);
        }
    }
    // encrypt here...
    for (File f : filesToProcess) {
        encryptFile(f, formInfo);
    }

    // encrypt the submission.xml as the last file...
    encryptFile(submissionXml, formInfo);

    return filesToProcess;
}

From source file:PathUtils.java

/**
 * Calculates the relative path between a specified root directory and a target path.
 *
 * @param root   The absolute path of the root directory.
 * @param target The path to the target file or directory.
 * @return The relative path between the specified root directory and the target path.
 * @throws IllegalArgumentException <ul><li>The root file cannot be null.</li><li>The target cannot be
 *                                  null.</li><li>The root file must be a directory.</li><li>The root file must be
 *                                  absolute.</li></ul>
 *///  www. j a v  a  2  s  . c  o m
public static String relativize(final File root, final File target) throws IllegalArgumentException {
    if (root == null)
        throw new IllegalArgumentException("The root file cannot be null.");
    if (target == null)
        throw new IllegalArgumentException("The target cannot be null.");
    if (!root.isDirectory())
        throw new IllegalArgumentException("The root file must be a directory.");
    if (!root.isAbsolute())
        throw new IllegalArgumentException("The root file must be absolute.");
    if (!target.isAbsolute())
        return target.toString();

    if (root.equals(target))
        return ".";

    // Deconstruct hierarchies
    final Deque<File> rootHierarchy = new ArrayDeque<File>();
    for (File f = root; f != null; f = f.getParentFile())
        rootHierarchy.push(f);
    final Deque<File> targetHierarchy = new ArrayDeque<File>();
    for (File f = target; f != null; f = f.getParentFile())
        targetHierarchy.push(f);

    // Trace common root
    while (rootHierarchy.size() > 0 && targetHierarchy.size() > 0
            && rootHierarchy.peek().equals(targetHierarchy.peek())) {
        rootHierarchy.pop();
        targetHierarchy.pop();
    }
    // Create relative path
    final StringBuilder sb = new StringBuilder(rootHierarchy.size() * 3 + targetHierarchy.size() * 32);
    while (rootHierarchy.size() > 0) {
        sb.append("..");
        rootHierarchy.pop();
        if (rootHierarchy.size() > 0 || targetHierarchy.size() > 0)
            sb.append(File.separator);
    }
    while (targetHierarchy.size() > 0) {
        sb.append(targetHierarchy.pop().getName());
        if (targetHierarchy.size() > 0)
            sb.append(File.separator);
    }
    return sb.toString();
}

From source file:brooklyn.util.os.Os.java

/** causes empty directories from subsubdir up to and including dir to be deleted on exit;
 * useful e.g. if we create  /tmp/brooklyn-test/foo/test1/  and someone else might create
 * /tmp/brooklyn-test/foo/test2/   and we'd like the last tear-down to result in /tmp/brooklyn-test  being deleted!
 * <p> /*from  www.j av a  2 s  . c o  m*/
 * returns number of directories queued for deletion so caller can check for errors if desired;
 * if dir is not an ancestor of subsubdir this logs a warning but does not throw  */
public static int deleteOnExitEmptyParentsUpTo(File subsubDirOrFile, File dir) {
    if (subsubDirOrFile == null || dir == null)
        return 0;

    List<File> dirsToDelete = new ArrayList<File>();
    File d = subsubDirOrFile;
    do {
        dirsToDelete.add(d);
        if (d.equals(dir))
            break;
        d = d.getParentFile();
    } while (d != null);

    if (d == null) {
        log.warn("File " + subsubDirOrFile + " has no ancestor " + dir
                + ": will not attempt to clean up with ancestors on exit");
        // dir is not an ancestor if subsubdir
        return 0;
    }

    for (File f : dirsToDelete)
        deleteOnExit(f);

    return dirsToDelete.size();
}

From source file:org.kalypso.commons.java.io.FileUtilities.java

/**
 * Returns true if childCandidate is stored under the path of parent, either directly or in a sub directory.
 * //from   w  w  w. j a v  a  2 s .c  o  m
 * @param parent
 * @param childCandidate
 * @return true if childCandidate is a child of the given parent.
 */
public static boolean isChildOf(final File parent, final File childCandidate) {
    File f = childCandidate;

    while (f != null) {
        if (f.equals(parent))
            return true;

        f = f.getParentFile();
    }

    return false;
}

From source file:org.limewire.util.FileUtils.java

/**
 * @return true if the two files are the same.  If they are both
 * directories returns true if there is at least one file that 
 * conflicts./*from w ww  . j  ava  2s  . c  o m*/
 */
public static boolean conflictsAny(File a, File b) {
    if (a.equals(b))
        return true;
    Set<File> unique = new HashSet<File>();
    unique.add(a);
    for (File recursive : getFilesRecursive(a, null))
        unique.add(recursive);

    if (unique.contains(b))
        return true;
    for (File recursive : getFilesRecursive(b, null)) {
        if (unique.contains(recursive))
            return true;
    }

    return false;

}

From source file:eu.stratosphere.configuration.GlobalConfiguration.java

private static File[] filterFilesBySuffix(final File dirToFilter, final String[] suffixes) {
    return dirToFilter.listFiles(new FilenameFilter() {
        @Override// w  ww  .  j av  a2 s . co m
        public boolean accept(final File dir, final String name) {
            for (String suffix : suffixes) {
                if (dir.equals(dirToFilter) && name != null && name.endsWith(suffix)) {
                    return true;
                }
            }

            return false;
        }
    });
}

From source file:org.limewire.util.FileUtils.java

/**
 * Determines if file 'a' is an ancestor of file 'b'.
 *//*  w ww . ja  v a  2 s. c om*/
public static final boolean isAncestor(File a, File b) {
    while (b != null) {
        if (b.equals(a))
            return true;
        b = b.getParentFile();
    }
    return false;
}

From source file:madkitgroupextension.export.Export.java

public static void updateFTP(FTPClient ftpClient, String _directory_dst, File _directory_src,
        File _current_file_transfert, File _current_directory_transfert)
        throws IOException, TransfertException {
    if (_current_directory_transfert == null || _directory_src.equals(_current_directory_transfert)) {
        try {//from  w  w w  . j av a 2 s .co m
            updateFTP(ftpClient, _directory_dst, _directory_src, _current_file_transfert);
        } catch (TransfertException e) {
            e.current_directory_transfert = _directory_src;
            throw e;
        }
    }
}