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.cloudifysource.dsl.internal.packaging.Packager.java

private static void copyExtendedServiceFiles(final Service service, final File recipeFile, final File extFolder)
        throws IOException {
    final LinkedList<String> extendedServicesPaths = service.getExtendedServicesPaths();

    File extendingScriptFile = new File(extFolder + "/" + recipeFile.getName());
    File currentExtendedServiceContext = recipeFile;

    for (final String extendedServicePath : extendedServicesPaths) {
        // Locate the extended service file in the destination path
        final File extendedServiceFile = locateServiceFile(currentExtendedServiceContext, extendedServicePath);
        // If the extended service exists in my directory, no need to copy
        // or change anything
        // This can happen if we have extension of services inside
        // application since the client
        // will prepare the extending service directory already and then it
        // will be prepared fully at the server
        if (extendedServiceFile.getParentFile().equals(recipeFile.getParentFile())) {
            continue;
        }//from  w ww .  jav  a2s.c om
        // Copy it to local dir with new name if needed
        final File localExtendedServiceFile = copyExtendedServiceFileAndRename(extendedServiceFile, extFolder);
        logger.finer(
                "copying locally extended script " + extendedServiceFile + " to " + localExtendedServiceFile);
        // Update the extending script extend property with the location of
        // the new extended service script
        updateExtendingScriptFileWithNewExtendedScriptLocation(extendingScriptFile, localExtendedServiceFile);
        // Copy remote resources locally
        final File rootScriptDir = extendedServiceFile.getParentFile();
        FileUtils.copyDirectory(rootScriptDir, extFolder, new FileFilter() {

            @Override
            public boolean accept(final File pathname) {
                if (!SVNFileFilter.getFilter().accept(pathname)) {
                    return false;
                }
                if (pathname.equals(extendedServiceFile)) {
                    return false;
                }
                if (pathname.isDirectory()) {
                    return true;
                }
                final String relativePath = pathname.getPath().replace(rootScriptDir.getPath(), "");
                final boolean accept = !new File(extFolder.getPath() + "/" + relativePath).exists();
                if (accept && logger.isLoggable(Level.FINEST)) {
                    logger.finest("copying extended script resource [" + pathname + "] locally");
                }
                return accept;

            }
        });
        // Replace context extending script file for multiple level
        // extension
        extendingScriptFile = localExtendedServiceFile;
        currentExtendedServiceContext = extendedServiceFile;
    }
}

From source file:org.nuxeo.osgi.application.loader.FrameworkLoader.java

protected static Environment createEnvironment(File home, Map<String, Object> hostEnv) {
    Properties sysprops = System.getProperties();
    sysprops.setProperty(Environment.NUXEO_RUNTIME_HOME, home.getAbsolutePath());

    Environment env = Environment.getDefault();
    if (env == null) {
        env = new Environment(home);
    }//  w  w  w . j  a va  2s  .co  m
    if (!home.equals(env.getRuntimeHome())) {
        env.setRuntimeHome(home);
    }

    String v = (String) hostEnv.get(HOST_NAME);
    env.setHostApplicationName(v == null ? Environment.NXSERVER_HOST : v);
    v = (String) hostEnv.get(HOST_VERSION);
    if (v != null) {
        env.setHostApplicationVersion((String) hostEnv.get(HOST_VERSION));
    }

    v = getEnvProperty(Environment.NUXEO_DATA_DIR, hostEnv, sysprops, true);
    if (v != null) {
        env.setData(new File(v));
    } else {
        sysprops.setProperty(Environment.NUXEO_DATA_DIR, env.getData().getAbsolutePath());
    }

    v = getEnvProperty(Environment.NUXEO_LOG_DIR, hostEnv, sysprops, true);
    if (v != null) {
        env.setLog(new File(v));
    } else {
        sysprops.setProperty(Environment.NUXEO_LOG_DIR, env.getLog().getAbsolutePath());
    }

    v = getEnvProperty(Environment.NUXEO_TMP_DIR, hostEnv, sysprops, true);
    if (v != null) {
        env.setTemp(new File(v));
    } else {
        sysprops.setProperty(Environment.NUXEO_TMP_DIR, env.getTemp().getAbsolutePath());
    }

    v = getEnvProperty(Environment.NUXEO_CONFIG_DIR, hostEnv, sysprops, true);
    if (v != null) {
        env.setConfig(new File(v));
    } else {
        sysprops.setProperty(Environment.NUXEO_CONFIG_DIR, env.getConfig().getAbsolutePath());
    }

    v = getEnvProperty(Environment.NUXEO_WEB_DIR, hostEnv, sysprops, true);
    if (v != null) {
        env.setWeb(new File(v));
    } else {
        sysprops.setProperty(Environment.NUXEO_WEB_DIR, env.getWeb().getAbsolutePath());
    }

    v = (String) hostEnv.get(ARGS);
    if (v != null) {
        env.setCommandLineArguments(v.split("\\s+"));
    } else {
        env.setCommandLineArguments(new String[0]);
    }
    return env;
}

From source file:org.dita.dost.util.FileUtils.java

/**
 * Determines whether the parent directory contains the child element (a file or directory)
 * /*from   w w w .j  av  a  2s. c  o  m*/
 * @param directory the file to consider as the parent
 * @param child the file to consider as the child
 * @return true is the candidate leaf is under by the specified composite, otherwise false
 * @throws IOException
 */
public static boolean directoryContains(final File directory, final File child) {
    final File d = new File(normalize(directory.getAbsolutePath()));
    final File c = new File(normalize(child.getAbsolutePath()));
    if (d.equals(c)) {
        return false;
    } else {
        return c.getPath().startsWith(d.getPath());
    }
}

From source file:ch.njol.skript.command.Commands.java

public static int unregisterCommands(final File script) {
    int numCommands = 0;
    final Iterator<ScriptCommand> commandsIter = commands.values().iterator();
    while (commandsIter.hasNext()) {
        final ScriptCommand c = commandsIter.next();
        if (script.equals(c.getScript())) {
            numCommands++;/*  w ww . j  a  v a 2s.c om*/
            c.unregisterHelp();
            if (commandMap != null) {
                assert cmKnownCommands != null;// && cmAliases != null;
                c.unregister(commandMap, cmKnownCommands, cmAliases);
            }
            commandsIter.remove();
        }
    }
    return numCommands;
}

From source file:org.dkf.jed2k.android.LollipopFileSystem.java

private static String[] getExtSdCardPaths(Context context) {
    List<String> paths = new ArrayList<>();
    File[] externals = ContextCompat.getExternalFilesDirs(context, "external");
    File external = context.getExternalFilesDir("external");
    for (int i = 0; i < externals.length; i++) {
        File file = externals[i];
        if (file != null && !file.equals(external)) {
            String absolutePath = file.getAbsolutePath();
            int index = absolutePath.lastIndexOf("/Android/data");
            if (index >= 0) {
                String path = absolutePath.substring(0, index);
                try {
                    path = new File(path).getCanonicalPath();
                } catch (IOException e) {
                    // Keep non-canonical path.
                }//from ww w. j a v a  2 s .  co  m
                paths.add(path);
            } else {
                LOG.warn("ext sd card path wrong: {}", absolutePath);
            }
        }
    }
    // special hard coded paths for more security
    for (String path : FIXED_SDCARD_PATHS) {
        if (!paths.contains(path)) {
            paths.add(path);
        }
    }

    return paths.toArray(new String[0]);
}

From source file:com.cloudera.flume.agent.FlumeNode.java

/**
 * This function checks the agent logs dir to make sure that the process has
 * the ability to the directory if necesary, that the path if it does exist is
 * a directory, and that it can infact create files inside of the directory.
 * If it fails any of these, it throws an exception.
 * //  w ww.  j av a2 s  . co  m
 * Finally, it checks to see if the path is in /tmp and warns the user that
 * this may not be the best idea.
 */
public static void nodeConfigChecksOk() throws IOException {
    // TODO (jon) if we add more checks in here, make the different managers
    // responsible for throwing an Exception on construction instead.

    FlumeConfiguration conf = FlumeConfiguration.get();

    String s = conf.getAgentLogsDir();
    File f = new File(s);

    if (!FileUtil.makeDirs(f)) {
        throw new IOException("Path to Log dir cannot be created: '" + s + "'.  Check permissions?");
    }

    if (!f.isDirectory()) {
        throw new IOException("Log dir '" + s + "' already exists as a file.  Check log dir path.");
    }

    File f2 = null;
    try {
        f2 = File.createTempFile("initcheck", ".test", f);
    } catch (IOException e) {
        throw new IOException("Failure to write in log directory: '" + s + "'.  Check permissions?");
    }
    if (!f2.delete()) {
        throw new IOException("Unable to delete " + f2 + " from log directory "
                + "(but writing succeeded) - something is strange here");
    }

    File tmp = new File("/tmp");
    File cur = f;
    while (cur != null) {
        if (cur.equals(tmp)) {
            LOG.warn("Log directory is writing inside of /tmp.  This data may not survive reboot!");
            break;
        }
        cur = cur.getParentFile();
    }
}

From source file:com.frostwire.android.LollipopFileSystem.java

private static String[] getExtSdCardPaths(Context context) {
    List<String> paths = new ArrayList<>();
    File[] externals = ContextCompat.getExternalFilesDirs(context, "external");
    File external = context.getExternalFilesDir("external");
    for (File file : externals) {
        if (file != null && !file.equals(external)) {
            String absolutePath = file.getAbsolutePath();
            int index = absolutePath.lastIndexOf("/Android/data");
            if (index >= 0) {
                String path = absolutePath.substring(0, index);
                try {
                    path = new File(path).getCanonicalPath();
                } catch (IOException e) {
                    // Keep non-canonical path.
                }/*from   w w w .  j a  v  a  2s  . c  o m*/
                paths.add(path);
            } else {
                LOG.warn("ext sd card path wrong: " + absolutePath);
            }
        }
    }
    // special hard coded paths for more security
    for (String path : FIXED_SDCARD_PATHS) {
        if (!paths.contains(path)) {
            paths.add(path);
        }
    }

    return paths.toArray(new String[0]);
}

From source file:org.openflexo.toolbox.FileUtils.java

public static boolean directoryContainsFile(File directory, File file) {
    if (file.equals(directory)) {
        return true;
    }// ww  w  .j a v a 2s . c  o m
    if (file.getParentFile() != null) {
        return directoryContainsFile(directory, file.getParentFile());
    }
    return false;
}

From source file:de.decidr.ui.controller.VaadinTenantThemeInstaller.java

/**
 * Installs the custom theme of the given tenant, if that tenant has a
 * custom theme. If a current or outdated version of the custom theme is
 * already installed, it will be overwritten.
 * /*  w w  w.  ja  v  a 2 s  .  c om*/
 * @param tenantId
 * @return whether a custom theme was successfully installed. Also returns
 *         true if the custom theme was already installed and has been
 *         overwritten.
 */
public static boolean installLocally(long tenantId) {
    TenantFacade tenantFacade = ModelFacades.getTenantFacade();
    InputStream cssContents = null;
    InputStream logoFileContents = null;

    /*
     * The custom theme is created by copying the default theme and
     * replacing the logo and css files
     */
    File template = null;
    File destination = null;
    /*
     * Target files to replace
     */
    File cssFile = UIConventions.getCssFile(tenantId);
    File logoFile = UIConventions.getLogoFile(tenantId);

    try {
        cssContents = tenantFacade.getCurrentColorScheme(tenantId);
        logoFileContents = tenantFacade.getLogo(tenantId);

        /*
         * Create a copy of the default theme.
         */
        template = UIConventions.getThemeDirectory(UIConventions.DEFAULT_THEME_NAME);
        destination = UIConventions.getThemeDirectory(UIConventions.getThemeName(tenantId));
        if (!template.equals(destination)) {
            FileUtils.copyDirectory(template, destination);
        }

        /*
         * Replace CSS and logo
         */
        replaceFile(cssFile, cssContents);
        replaceFile(logoFile, logoFileContents);
    } catch (IOException e) {
        logger.error("Cannot create custom tenant theme from template", e);
        try {
            /*
             * Undo creation of new directory if possible
             */
            if (destination != null && destination.isDirectory()) {
                FileUtils.deleteDirectory(destination);
            }
        } catch (IOException undoException) {
            if (destination != null) {
                logger.error("Cannot undo creation of destination directory. We have a file corpse: "
                        + destination.getAbsolutePath(), undoException);
            }
        }
        return false;
    } catch (TransactionException e) {
        DecidrUI.getCurrent().getMainWindow().addWindow(new TransactionErrorDialogComponent(e));
        return false;
    } finally {
        IOUtils.closeQuietly(cssContents);
        IOUtils.closeQuietly(logoFileContents);
    }

    return true;
}

From source file:org.jfrog.build.extractor.clientConfiguration.util.PublishedItemsHelper.java

/**
 * Checks if a given directory is an ansector (file system speaking)
 * of a certain directory//from ww  w .j  a v a  2 s.  co m
 *
 * @param ancestor The directory to check if it's an ancestor of
 * @param child    The child directory
 * @return true if ancestor if an ancestor of child, false otherwise
 * @throws IOException
 */
private static boolean isAncestor(File ancestor, File child) throws IOException {
    File parent = child;
    do {
        if (parent == null) {
            return false;
        }
        if (parent.equals(ancestor)) {
            return true;
        }
        parent = getParentFile(parent);
    } while (true);
}