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:com.bedatadriven.renjin.appengine.AppEngineContextFactory.java

@VisibleForTesting
static String findHomeDirectory(File servletContextRoot, String sexpClassPath) throws IOException {

    LOG.fine("Found SEXP in '" + sexpClassPath);

    File jarFile = jarFileFromResource(sexpClassPath);
    StringBuilder homePath = new StringBuilder();
    homePath.append('/').append(jarFile.getName()).append("!/r");

    File parent = jarFile.getParentFile();
    while (!servletContextRoot.equals(parent)) {
        if (parent == null) {
            throw new IllegalStateException(
                    "Expected the renjin-core jar to be in the WEB-INF, bound found it in:\n"
                            + jarFile.toString() + "\nAre you sure you are running in a servlet environment?");
        }/*w  w w.  ja  v a 2s. co  m*/
        homePath.insert(0, parent.getName());
        homePath.insert(0, '/');
        parent = parent.getParentFile();
    }
    homePath.insert(0, "jar:file://");

    return homePath.toString();
}

From source file:org.opennms.netmgt.config.SnmpPeerFactory.java

/**
 * <p>setFile</p>/*w ww.  ja  va  2s  .co  m*/
 *
 * @param configFile a {@link java.io.File} object.
 */
public static synchronized void setFile(final File configFile) {
    final File oldFile = m_configFile;
    m_configFile = configFile;

    // if the file changed then we need to reload the config
    if (oldFile == null || m_configFile == null || !oldFile.equals(m_configFile)) {
        m_singleton = null;
        m_loaded = false;
    }
}

From source file:adalid.commons.util.FilUtils.java

public static Map<String, File> parentDirectoriesMap(File file, File top) {
    Map<String, File> map = new LinkedHashMap<>();
    File parent;
    File topdir = isVisibleDirectory(top) ? top : null;
    if (isVisibleDirectory(file) || isVisibleFile(file)) {
        parent = file.getParentFile();//  w ww  .  j  ava  2  s.  c om
        if (isVisibleDirectory(parent)) {
            if (parent.equals(topdir)) {
            } else {
                map.putAll(parentDirectoriesMap(parent, topdir));
                map.put(parent.getPath(), parent);
            }
        }
    }
    return map;
}

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

/**
 * Loads the configuration files from the specified directory.
 * /* w  ww  .  j av  a 2  s.  c  o m*/
 * @param configDir
 *        the directory which contains the configuration files
 */
public static void loadConfiguration(final String configDir) {

    if (configDir == null) {

        LOG.warn("Given configuration directory is null, cannot load configuration");
        return;
    }

    final File confDirFile = new File(configDir);
    if (!(confDirFile.exists() && confDirFile.isDirectory())) {
        LOG.warn("The given configuration directory name '" + configDir + "'(" + confDirFile.getAbsolutePath()
                + ") does not describe an existing directory.");
        return;
    }

    // get all XML files in the directory
    final File[] files = confDirFile.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(final File dir, final String name) {
            return dir.equals(confDirFile) && name != null && name.endsWith(".xml");
        }

    });
    if (files == null || files.length == 0) {
        LOG.warn("Unable to get the contents of the config directory '" + configDir + "' ("
                + confDirFile.getAbsolutePath() + ").");
        return;
    }

    // load each xml file
    for (File f : files) {
        get().loadResource(f);
    }

    // Store the path to the configuration directory itself
    if (configuration != null) {
        configuration.confData.put(CONFIGDIRKEY, configDir);
    }
}

From source file:com.google.dart.tools.core.utilities.io.FileUtilities.java

/**
 * Return <code>true</code> if the given parent directory is either the same as or a parent of the
 * given child directory.//from   w  w  w  .ja  va2s  .c  o m
 * 
 * @param parentDirectory the directory that might be a parent of the child directory
 * @param childDirectory the directory that might be a child of the parent directory
 * @return <code>true</code> if the given parent directory is a parent of the given child
 *         directory
 */
public static boolean isParentOf(File parentDirectory, File childDirectory) {
    File directory = childDirectory;
    while (directory != null) {
        if (parentDirectory.equals(directory)) {
            return true;
        }
        directory = directory.getParentFile();
    }
    return false;
}

From source file:org.broadinstitute.gatk.utils.io.IOUtils.java

/**
 * Returns true if the file is a special file.
 * @param file File path to check.//w  w w  .  j a v  a2 s .  c  o m
 * @return true if the file is a special file.
 */
public static boolean isSpecialFile(File file) {
    return file != null && (file.getAbsolutePath().startsWith("/dev/") || file.equals(DEV_DIR));
}

From source file:org.eclipse.ecr.common.utils.FileUtils.java

/**
 * Copies source to destination. If source and destination are the same,
 * does nothing. Both single files and directories are handled.
 *
 * @param src the source file or directory
 * @param dst the destination file or directory
 * @throws IOException//from   ww  w  . j  a v  a2s . c o m
 */
public static void copy(File src, File dst) throws IOException {
    if (src.equals(dst)) {
        return;
    }
    if (src.isFile()) {
        copyFile(src, dst);
    } else {
        copyTree(src, dst);
    }
}

From source file:org.apache.flex.compiler.internal.projects.SourcePathManager.java

public static String computeQName(File ancestor, File descendent) {
    assert ancestor.equals(FilenameNormalization.normalize(ancestor));
    assert descendent.equals(FilenameNormalization.normalize(descendent));
    StringBuilder result = new StringBuilder();
    File current = descendent.getParentFile();
    result.insert(0, FilenameUtils.getBaseName(descendent.getPath()));
    while (current != null) {
        if (current.equals(ancestor))
            return result.toString();
        result.insert(0, '.');
        result.insert(0, FilenameUtils.getBaseName(current.getPath()));
        current = current.getParentFile();
    }//from w  w  w. ja v a 2s.c  o  m
    return null;
}

From source file:it.geosolutions.tools.io.file.Copy.java

/**
 * Copy a file (preserving data) to a destination (which can be on nfs)
 * waiting (at least) 'seconds' seconds for its propagation.
 * //from   w ww. j  a v  a 2s  .  c o m
 * @param source
 * @param dest
 * @param overwrite
 *            if false and destination exists() do not overwrite the file
 * @param seconds
 *            to wait (maximum) for nfs propagate. If -1 no check is
 *            performed.
 * @return the copied file if success, null if not.
 */
public static File copyFileToNFS(File source, File dest, boolean overwrite, final int seconds) {
    if (source != null && dest != null) {
        if (dest.exists()) {
            // source == destination
            if (source.equals(dest)) {
                // YES
                // (dest.exists, !overwrite, source==dest) -> return source
                if (LOGGER.isErrorEnabled())
                    LOGGER.error("Unable to copy file to: \'" + dest.getAbsolutePath()
                            + "\' source and destination are the same! (overwrite is set to \'" + overwrite
                            + "\'). Returning source.");
                return source;
            }
            // overwrite?
            if (!overwrite) {
                // NO
                // source != destination
                if (!dest.exists()) {
                    // NO
                    // (dest.exists, !overwrite, source!=dest) -> fail
                    if (LOGGER.isErrorEnabled())
                        LOGGER.error("Failed to copy file to: \'" + dest.getAbsolutePath()
                                + "\' destination exists! (overwrite is set to \'" + overwrite + "\').");
                    return null;
                }
            }
        }
        return copyFileToNFS(source, dest, seconds);

    } else {
        // NullPointerException - if source or destination is null
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Source or destination is null.");
        return null;
    }
}

From source file:com.wavemaker.commons.util.IOUtils.java

private static void makeDirectoriesRecurse(File dir, File topLevel) throws FileAccessException {

    // if we're at the topLevel end recursion
    if (dir.equals(topLevel)) {
        return;/*  w w  w. j a v a2 s . c o m*/
    }

    // if we're at the filesystem root, error
    for (File root : File.listRoots()) {
        if (dir.equals(root)) {
            throw new FileAccessException(MessageResource.UTIL_FILEUTILS_REACHEDROOT, root, topLevel);
        }
    }

    // make & check parent directories
    makeDirectoriesRecurse(dir.getParentFile(), topLevel);

    // make this directory
    if (!dir.exists()) {
        dir.mkdir();
    }
}