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.codehaus.mojo.javascript.AbstractCompressMojo.java

private long compress(JSCompressor jscompressor, String file) throws MojoExecutionException {
    String name = file;/*from   www .j  a va  2s.  c o m*/
    if (getExtension() != null) {
        int ext = file.lastIndexOf('.');
        name = file.substring(0, ext) + "-" + getExtension() + file.substring(ext);
    }
    File compressed = new File(getOutputDirectory(), name);
    compressed.getParentFile().mkdirs();
    File in = new File(getSourceDirectory(), file);
    if (in.equals(compressed)) {
        try {
            File temp = File.createTempFile("compress", ".js");
            long size = compress(in, temp, jscompressor);
            FileUtils.copyFile(temp, compressed);
            temp.delete();
            return size;
        } catch (IOException e) {
            throw new MojoExecutionException("Error creating temp file for compression", e);
        }
    } else {
        return compress(in, compressed, jscompressor);
    }
}

From source file:com.enonic.cms.core.resource.FileResourceServiceImpl.java

private boolean isSubFolderOf(final File fromFile, final File toFile) {
    File parent = toFile.getParentFile();

    while (parent != null) {
        if (parent.equals(resourceRoot)) {
            return false;
        }//from w  ww.  j  av a 2s . c o  m

        if (parent.equals(fromFile)) {
            return true;
        }

        parent = parent.getParentFile();
    }

    return false;
}

From source file:org.eu.gasp.core.internal.DefaultPluginRegistry.java

private boolean isFileRegistered(File file) {
    if (file == null) {
        throw new NullPointerException("file");
    }//from   w ww.j a  v  a 2 s  . c  om

    for (final PluginData pluginData : plugins.values()) {
        if (file.equals(pluginData.file)) {
            return true;
        }
    }

    return false;
}

From source file:org.opencastproject.composer.gstreamer.GSEncodingProfileScanner.java

@Override
public void uninstall(File artifact) throws Exception {
    for (Iterator<EncodingProfile> iter = profiles.values().iterator(); iter.hasNext();) {
        EncodingProfile profile = iter.next();
        if (artifact.equals(profile.getSource())) {
            logger.info("Uninstalling profile {}", profile.getIdentifier());
            iter.remove();/* ww  w.jav  a2  s .  c  o  m*/
        }
    }
}

From source file:org.jpublish.page.filesystem.FileSystemPageManagerWithContextDefault.java

/**
 * browse the parent folders for searching the default page descriptor
 *
 * @param root the root directory/*from ww w  . j a va  2s  .  c  o  m*/
 * @param path the requested path
 * @return default file
 */
private File getPathContextDefaultPage(File root, String path) {

    String defPage = File.separatorChar + getDefaultPath();
    File parentDir = new File(root, path.substring(0, path.lastIndexOf("/")));
    File rootDefaultPage = new File(root, defPage);
    File defaultFile = new File(parentDir, defPage);

    while (!defaultFile.exists() && !(rootDefaultPage.equals(defaultFile))) {
        parentDir = new File(parentDir.getParent());
        defaultFile = new File(parentDir + defPage);
    }
    return defaultFile;

}

From source file:org.photovault.imginfo.VolumeBase.java

/**
 *     Checks whether a certain file is part  of the volume (i.e. in the directory 
 *     hierarchy under the base directory. Note that existence of the file is not 
 *     ckecked, nor whether the file is really an instance of a PhotoInfo.
 * @return true if the file belongs to the volume, false otherwise
 * @param f File // ww w .ja  va 2  s .c om
 * @throws IOException if is an error when creating canonical form of f
 */
@Transient
public boolean isFileInVolume(File f) throws IOException {
    boolean isInVolume = false;

    if (f == null) {
        return false;
    }

    // First get the canonical forms of both f and volumeBaseDir
    // After that check if f or some of its parents matches f
    File basedir = getBaseDir();
    if (basedir == null) {
        return false;
    }
    File vbdCanon = basedir.getCanonicalFile();
    File fCanon = f.getCanonicalFile();
    File p = fCanon;
    while (p != null) {
        if (p.equals(vbdCanon)) {
            isInVolume = true;
            break;
        }
        p = p.getParentFile();
    }
    return isInVolume;

}

From source file:org.apache.pluto.util.assemble.file.FileAssembler.java

public void assemble(AssemblerConfig config) throws UtilityException {
    try {//from   w w w  .ja  v a  2  s . c o m
        final File webappDescriptor = config.getWebappDescriptor();
        InputStream webXmlIn = new FileInputStream(webappDescriptor);

        final File portletDescriptor = config.getPortletDescriptor();
        InputStream portletXmlIn = new FileInputStream(portletDescriptor);

        final File destinationDescriptor = config.getDestination();
        if (webappDescriptor.equals(destinationDescriptor)) {
            final File tempXml = File.createTempFile(webappDescriptor.getName() + ".", ".tmp");
            final FileOutputStream webXmlOut = new FileOutputStream(tempXml);

            this.updateWebappDescriptor(webXmlIn, portletXmlIn, webXmlOut, config.getDispatchServletClass());

            //Move the temp file to the destination location
            destinationDescriptor.delete();
            // renameTo() is impl-specific
            boolean success = tempXml.renameTo(destinationDescriptor);
            if (!success) {
                FileUtils.copyFile(tempXml, destinationDescriptor);
            }
        } else {
            destinationDescriptor.getParentFile().mkdirs();
            final FileOutputStream webXmlOut = new FileOutputStream(destinationDescriptor);
            this.updateWebappDescriptor(webXmlIn, portletXmlIn, webXmlOut, config.getDispatchServletClass());
        }
    } catch (IOException ex) {
        throw new UtilityException(ex.getMessage(), ex, null);
    }
}

From source file:eu.openanalytics.rsb.component.JobProcessor.java

public void process(final MultiFilesJob job) throws Exception {
    process(job, new JobRunner() {
        @Override//from  w ww .ja v  a2s . com
        public AbstractResult<File[]> runOn(final RServi rServi) throws Exception {
            final Set<String> filesUploadedToR = new HashSet<String>();

            // locate and upload the R script
            final File rScriptFile = getRScriptFile(job);

            uploadFileToR(rServi, rScriptFile, filesUploadedToR);

            // optionally uploads a Sweave file
            final String sweaveFileFromCatalog = (String) getUploadableJobMeta(job)
                    .get(Constants.SWEAVE_FILE_CONFIGURATION_KEY);

            if (sweaveFileFromCatalog != null) {
                final File sweaveFile = getCatalogManager().internalGetCatalogFile(CatalogSection.SWEAVE_FILES,
                        job.getApplicationName(), sweaveFileFromCatalog);

                if (!sweaveFile.isFile()) {
                    throw new IllegalArgumentException("Invalid catalog Sweave file reference in job: " + job);
                }

                uploadFileToR(rServi, sweaveFile, filesUploadedToR);
            }

            // upload the job files (except the R Script which has already been
            // taken care of)
            for (final File jobFile : job.getFiles()) {
                if (!jobFile.equals(rScriptFile)) {
                    uploadFileToR(rServi, jobFile, filesUploadedToR);
                }
            }

            // upload the configuration file to R
            uploadPropertiesToR(rServi, getUploadableJobMeta(job), filesUploadedToR);

            // hit R
            executeScriptOnR(rServi, rScriptFile.getName());

            final MultiFilesResult result = job.buildSuccessResult();

            // download the result files but not the uploaded ones nor the log
            // file
            final Set<String> filesToDownload = getFilesInRWorkspace(rServi);
            filesToDownload.removeAll(filesUploadedToR);
            filesToDownload.remove(Constants.DEFAULT_R_LOG_FILE);
            for (final String fileToDownload : filesToDownload) {
                final File resultFile = result.createNewResultFile(fileToDownload);
                final FileOutputStream fos = new FileOutputStream(resultFile);
                rServi.downloadFile(fos, fileToDownload, 0, null);
                IOUtils.closeQuietly(fos);
            }

            return result;
        }

        private Map<String, Serializable> getUploadableJobMeta(final Job job) {
            final Map<String, Serializable> meta = new HashMap<String, Serializable>(job.getMeta());

            if ((JobProcessor.this.getConfiguration().isPropagateSecurityContext())
                    && (StringUtils.isNotBlank(job.getUserName()))) {
                meta.put("rsbSecure", true);
                meta.put("rsbUserPrincipal", job.getUserName());
            }

            return meta;
        }

        private File getRScriptFile(final MultiFilesJob job) {
            final String rScriptFromCatalog = (String) getUploadableJobMeta(job)
                    .get(Constants.R_SCRIPT_CONFIGURATION_KEY);

            return rScriptFromCatalog != null ? getRScriptFileFromCatalog(rScriptFromCatalog, job)
                    : getRScriptFileFromJob(job);
        }

        private File getRScriptFileFromCatalog(final String rScriptFromCatalog, final MultiFilesJob job) {
            final File rScriptFile = getCatalogManager().internalGetCatalogFile(CatalogSection.R_SCRIPTS,
                    job.getApplicationName(), rScriptFromCatalog);

            if ((rScriptFile == null) || (!rScriptFile.isFile())) {
                throw new IllegalArgumentException("No R script has been found for job: " + job
                        + ", in the catalog under the name: " + rScriptFromCatalog);
            } else {
                return rScriptFile;
            }
        }

        private File getRScriptFileFromJob(final MultiFilesJob job) {
            if ((job.getRScriptFile() == null) || (!job.getRScriptFile().isFile())) {
                throw new IllegalArgumentException("No R script has been found for job: " + job);
            } else {
                return job.getRScriptFile();
            }
        }
    }, false);
}

From source file:edu.unc.lib.dl.ingest.sip.METSPackageFileValidator.java

/**
 * Checks that there are as many files packaged as there are non-staged file references. Computes and compares the
 * MD5 digest of packaged files that have a checksum in METS. Checks access to all files referenced in staging
 * locations./*from ww  w . ja va2 s .  co m*/
 *
 * @param mets
 * @param metsPack
 * @param aip
 * @throws IngestException
 */
@SuppressWarnings("unchecked")
public void validateFiles(Document mets, METSPackageSIP metsPack) throws IngestException {
    StringBuffer errors = new StringBuffer();
    List<File> manifestFiles = new ArrayList<File>();
    List<String> missingFiles = new ArrayList<String>();
    List<String> badChecksumFiles = new ArrayList<String>();

    // find missing or corrupt files listed in manifest
    try {
        for (Element fileEl : (List<Element>) allFilesXpath.selectNodes(mets)) {
            String href = null;
            try {
                href = fileEl.getChild("FLocat", JDOMNamespaceUtil.METS_NS).getAttributeValue("href",
                        JDOMNamespaceUtil.XLINK_NS);
                URI uri = new URI(href);
                if (uri.getScheme() != null && !uri.getScheme().contains("file")) {
                    continue;
                }
            } catch (URISyntaxException e) {
                errors.append("Cannot parse file location: " + e.getLocalizedMessage() + " (" + href + ")");
                missingFiles.add(href);
                continue;
            } catch (NullPointerException e) {
                errors.append("A file location is missing for file ID: " + fileEl.getAttributeValue("ID"));
                continue;
            }
            File file = null;
            // locate the file and check that it exists
            try {
                log.debug("Looking in SIP");
                file = metsPack.getFileForLocator(href);
                file.equals(file);
                manifestFiles.add(file);
                log.debug("FILE IS IN METSPackage: " + file.getPath());
                if (file == null || !file.exists()) {
                    missingFiles.add(href);
                    continue;
                }
            } catch (IOException e) {
                log.debug(e);
                missingFiles.add(href);
                errors.append(e.getMessage());
            }

            String checksum = fileEl.getAttributeValue("CHECKSUM");
            if (checksum != null) {
                log.debug("found a checksum in METS");
                Checksum checker = new Checksum();
                try {
                    String sum = checker.getChecksum(file);
                    if (!sum.equals(checksum.toLowerCase())) {
                        log.debug("Checksum failed for file: " + href + " (METS says " + checksum
                                + ", but we got " + sum + ")");
                        badChecksumFiles.add(href);
                    }
                    log.debug("METS manifest checksum was verified for file: " + href);
                } catch (IOException e) {
                    throw new IngestException("Checksum failed to find file: " + href);
                }
            }
        }
    } catch (JDOMException e1) {
        throw new Error("Unexpected JDOM Exception", e1);
    }

    // TODO: account for local (not inline xmlData) MODS files
    // see if there are extra files in the SIP
    List<String> extraFiles = new ArrayList<String>();

    if (metsPack.getSIPDataDir() != null) {
        int zipPathLength = 0;
        try {
            zipPathLength = metsPack.getSIPDataDir().getCanonicalPath().length();

            for (File received : metsPack.getDataFiles()) {
                if (!manifestFiles.contains(received) && received.compareTo(metsPack.getMetsFile()) != 0) {
                    extraFiles.add("file://" + received.getCanonicalPath().substring(zipPathLength));
                }
            }
        } catch (IOException e) {
            throw new Error("Unexpected IO Exception trying to get path of a known file.", e);
        }
    }
    if (missingFiles.size() > 0 || badChecksumFiles.size() > 0 || extraFiles.size() > 0) {
        // We have an error here...
        String msg = "The files submitted do not match those listed in the METS manifest.";
        FilesDoNotMatchManifestException e = new FilesDoNotMatchManifestException(msg);
        e.setBadChecksumFiles(badChecksumFiles);
        e.setExtraFiles(extraFiles);
        e.setMissingFiles(missingFiles);
        throw e;
    }
}

From source file:org.jajuk.util.UtilSystem.java

/**
 * Checks if is ancestor.//from   www  .j  av a  2s. c  o  m
 * 
 * @param file1 potential ancestor
 * @param file2 potential child
 * 
 * @return whether file1 is a file2 ancestor
 */
public static boolean isAncestor(final File file1, final File file2) {
    File fParent = file2.getParentFile();
    boolean bOut = false;
    while (fParent != null) {
        if (fParent.equals(file1)) {
            bOut = true;
            break;
        }
        fParent = fParent.getParentFile();
    }
    return bOut;
}