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:ru.emdev.ldap.util.EmDevSchemaLdifExtractor.java

/**
 * Calculates the destination file./*from w w w .  java  2s  . c  o  m*/
 *
 * @param resource the source file
 * @return the destination file's parent directory
 */
private File getDestinationFile(File resource) {
    File parent = resource.getParentFile();
    Stack<String> fileComponentStack = new Stack<String>();
    fileComponentStack.push(resource.getName());

    while (parent != null) {
        if (parent.getName().equals("schema")) {
            // All LDIF files besides the schema.ldif are under the 
            // schema/schema base path. So we need to add one more 
            // schema component to all LDIF files minus this schema.ldif
            fileComponentStack.push("schema");

            return assembleDestinationFile(fileComponentStack);
        }

        fileComponentStack.push(parent.getName());

        if (parent.equals(parent.getParentFile()) || parent.getParentFile() == null) {
            throw new IllegalStateException(I18n.err(I18n.ERR_08005));
        }

        parent = parent.getParentFile();
    }

    /*
            
       this seems retarded so I replaced it for now with what is below it
       will not break from loop above unless parent == null so the if is
       never executed - just the else is executed every time
            
    if ( parent != null )
    {
    return assembleDestinationFile( fileComponentStack );
    }
    else
    {
    throw new IllegalStateException( "parent cannot be null" );
    }
            
    */

    throw new IllegalStateException(I18n.err(I18n.ERR_08006));
}

From source file:com.xindian.mvc.result.velocity.WebappResourceLoader.java

/**
 * Checks to see if a resource has been deleted, moved or modified.
 * //from  www.ja  v a 2 s.  c  o  m
 * @param resource
 *            Resource The resource to check for modification
 * @return boolean True if the resource has been modified
 */
public boolean isSourceModified(Resource resource) {
    String rootPath = servletContext.getRealPath("/");
    if (rootPath == null) {
        // rootPath is null if the servlet container cannot translate the
        // virtual path to a real path for any reason (such as when the
        // content is being made available from a .war archive)
        return false;
    }

    // first, try getting the previously found file
    String fileName = resource.getName();
    File cachedFile = getCachedFile(rootPath, fileName);
    if (!cachedFile.exists()) {
        /* then the source has been moved and/or deleted */
        return true;
    }

    /*
     * check to see if the file can now be found elsewhere before it is
     * found in the previously saved path
     */
    File currentFile = null;
    for (int i = 0; i < paths.length; i++) {
        currentFile = new File(rootPath + paths[i], fileName);
        if (currentFile.canRead()) {
            /*
             * stop at the first resource found (just like in
             * getResourceStream())
             */
            break;
        }
    }

    /* if the current is the cached and it is readable */
    if (cachedFile.equals(currentFile) && cachedFile.canRead()) {
        /* then (and only then) do we compare the last modified values */
        return (cachedFile.lastModified() != resource.getLastModified());
    } else {
        /*
         * we found a new file for the resource or the resource is no longer
         * readable.
         */
        return true;
    }
}

From source file:org.cloudifysource.quality.iTests.test.cli.cloudify.cloud.templates.TemplateCreator.java

public TemplateDetails createTemplate(final String templateName, final File templateFile,
        final File templateFolder, final String uploadDirName) {

    TemplateDetails template = getNewTempalte();
    template.setTemplateFolder(templateFolder);

    // name// w  w  w  .jav  a 2 s . co m
    String updatedTemplateName = templateName;
    if (updatedTemplateName == null) {
        updatedTemplateName = templateFolder.getName();
    }
    template.setTemplateName(updatedTemplateName);

    // template file
    File updatedTemplateFile = templateFile;
    if (updatedTemplateFile == null) {
        updatedTemplateFile = new File(templateFolder,
                updatedTemplateName + DSLUtils.TEMPLATE_DSL_FILE_NAME_SUFFIX);
    } else {
        if (!updatedTemplateFile.exists()) {
            updatedTemplateFile = new File(templateFolder, updatedTemplateFile.getName());
        } else {
            if (!templateFolder.equals(updatedTemplateFile.getParentFile())) {
                try {
                    FileUtils.copyFileToDirectory(updatedTemplateFile, templateFolder);
                } catch (IOException e) {
                    Assert.fail("caught IOException while tried to copy template's file ["
                            + updatedTemplateFile.getAbsolutePath() + "] to folder ["
                            + templateFolder.getAbsolutePath() + "]. error was: " + e.getMessage());
                }
            }
        }
    }
    template.setTemplateFile(updatedTemplateFile);
    replaceStringInFile(getBasicTemplateFile(), updatedTemplateFile, TEMPLATE_NAME_STRING, updatedTemplateName);

    // upload directory
    String updatedUploadDirName = uploadDirName;
    if (updatedUploadDirName == null) {
        updatedUploadDirName = UPLOAD_DIR_NAME_PREFIX + "_" + templateFolder.getName();
    }
    template.setUploadDirName(updatedUploadDirName);
    final File uploadFolder = new File(templateFolder, updatedUploadDirName);
    uploadFolder.mkdir();

    // bootstrap management file
    final File updatedBootstrapManagementFile = new File(uploadFolder, BOOTSTRAP_MANAGEMENT_FILE_NAME);
    replaceStringInFile(getBasicBootstrapManagementFile(), updatedBootstrapManagementFile,
            UPLOAD_DIR_NAME_STRING, updatedUploadDirName);

    // properties file
    File templatePropsFile = createPropertiesFileForTemplate(template);
    template.setTemplatePropertiesFile(templatePropsFile);

    return template;
}

From source file:org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.java

private IVMInstall findVM(File jvmHome) {
    IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
    for (IVMInstallType type : types) {
        IVMInstall[] installs = type.getVMInstalls();
        for (IVMInstall install : installs) {
            if (jvmHome.equals(install.getInstallLocation())) {
                return install;
            }//from   ww  w. j  a va  2s .  c om
        }
    }
    return null;
}

From source file:org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java

private void addResourceFilesToProcess(CheckstyleExecutorRequest request, List<Resource> resources,
        Collection<File> files) throws IOException {
    for (Resource resource : resources) {
        if (resource.getDirectory() != null) {
            File resourcesDirectory = new File(resource.getDirectory());
            if (resourcesDirectory.isDirectory()) {
                String includes = request.getResourceIncludes();
                String excludes = request.getResourceExcludes();

                // MCHECKSTYLE-214: Only with project-root respect in/excludes, otherwise you'll get every file
                if (resourcesDirectory.equals(request.getProject().getBasedir())) {
                    String resourceIncludes = StringUtils.join(resource.getIncludes().iterator(), ",");
                    if (StringUtils.isEmpty(includes)) {
                        includes = resourceIncludes;
                    } else {
                        includes += "," + resourceIncludes;
                    }//from   w  w w  . j av a  2 s  . co  m

                    String resourceExcludes = StringUtils.join(resource.getExcludes().iterator(), ",");
                    if (StringUtils.isEmpty(excludes)) {
                        excludes = resourceExcludes;
                    } else {
                        excludes += "," + resourceExcludes;
                    }
                }

                List<File> resourceFiles = FileUtils.getFiles(resourcesDirectory, includes, excludes);
                files.addAll(resourceFiles);
                getLogger().debug("Added " + resourceFiles.size() + " resource files found in '"
                        + resourcesDirectory.getAbsolutePath() + "'.");
            } else {
                getLogger().debug("The resources directory '" + resourcesDirectory.getAbsolutePath()
                        + "' does not exist or is not a directory.");
            }
        }
    }
}

From source file:org.apache.maven.plugin.resource.loader.ProjectResourceLoader.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 . jav  a2s. com*/
 */
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 = templatePaths.get(fileName);
    File currentFile = null;

    for (int i = 0; currentFile == null && i < paths.size(); i++) {
        String testPath = 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.flex.forks.velocity.runtime.resource.loader.FileResourceLoader.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./*from  ww w . j  a  v a 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: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()));
    }/*ww  w.  jav  a2  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:org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.java

/**
 * Checks to see if a resource has been deleted, moved or modified. When
 * using the resource.loader.cache=true option
 * //from w  w w. j a  v a  2s .  c  om
 * @param resource
 *            Resource The resource to check for modification
 * 
 * @return boolean True if the resource has been modified
 */
public boolean isSourceModified(Resource resource) {

    String rootPath = servletContext.getRealPath("/");
    if (rootPath == null) {
        // RootPath is null if the servlet container cannot translate the
        // virtual path to a real path for any reason (such as when the
        // content is being made available from a .war archive)
        return false;
    }

    // first, try getting the previously found file
    String fileName = resource.getName();
    File cachedFile = getCachedFile(rootPath, fileName);
    if (!cachedFile.exists()) {
        // then the source has been moved and/or deleted
        return true;
    }

    /*
     * Check to see if the file can now be found elsewhere before it is
     * found in the previously saved path
     */
    File currentFile = null;
    for (int i = 0; i < paths.length; i++) {
        currentFile = new File(rootPath + paths[i], fileName);
        if (currentFile.canRead()) {
            /*
             * stop at the first resource found (just like in
             * getResourceStream())
             */
            break;
        }
    }

    // If the current is the cached and it is readable
    if (cachedFile.equals(currentFile) && cachedFile.canRead()) {
        // then (and only then) do we compare the last modified values
        return (cachedFile.lastModified() != resource.getLastModified());
    } else {
        // We found a new file for the resource or the resource is no longer
        // readable.
        return true;
    }
}

From source file:net.sf.nmedit.nomad.core.Nomad.java

public void openOrSelect(File file) {
    if (file.isDirectory())
        return;//  ww  w. jav a2  s.c  o  m

    // find out if file is already open

    for (Document d : getDocumentManager().getDocuments()) {
        if (file.equals(d.getFile())) {
            getDocumentManager().setSelection(d);
            return;
        }
    }

    Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class);
    while (iter.hasNext()) {
        FileService fs = iter.next();
        if (fs.isOpenFileOperationSupported()) {
            if (fs.getFileFilter().accept(file)) {
                int count = pageContainer.getDocumentCount();

                fs.open(file);
                int newCount = pageContainer.getDocumentCount();
                if (newCount > count) {
                    // condition may be false if fs.open() creates the document
                    // on the event dispatch thread
                    pageContainer.setSelectedIndex(newCount - 1);
                }
                return;
            }
        }
    }
}