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.jajuk.base.Collection.java

/**
 * Parse collection.xml file and put all collection information into memory
 *
 * @param file /*from   ww  w .j  a  v  a 2s .co m*/
 *
 * @throws SAXException the SAX exception
 * @throws ParserConfigurationException the parser configuration exception
 * @throws JajukException the jajuk exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void load(File file)
        throws SAXException, ParserConfigurationException, JajukException, IOException {
    // If we load the regular collection.xml file, try to recover it from previous crash
    java.io.File regularFile = SessionService.getConfFileByPath(Const.FILE_COLLECTION);
    if (file.equals(regularFile)) {
        UtilSystem.recoverFileIfRequired(regularFile);
    }
    Log.debug("Loading: " + file.getName());
    if (!file.exists()) {
        throw new JajukException(5, file.toString());
    }
    lTime = System.currentTimeMillis();
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    spf.setNamespaceAware(false);
    // See http://xerces.apache.org/xerces-j/features.html for details
    spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
    spf.setFeature("http://xml.org/sax/features/string-interning", true);
    SAXParser saxParser = spf.newSAXParser();
    saxParser.parse(file.toURI().toURL().toString(), getInstance());
}

From source file:net.risesoft.soa.asf.web.controller.SystemController.java

@RequestMapping({ "uploadLicense.do" })
@ResponseBody// w  w  w . java2s. com
public String uploadLicense(MultipartRequest multipartRequest) {
    if (!(this.bundleHelper.isDevMode())) {
        MultipartFile multipartFile = multipartRequest.getFile("licenseFile");

        File licenseFile = new File(
                System.getProperty("user.dir") + "/../license/" + multipartFile.getOriginalFilename());
        try {
            multipartFile.transferTo(licenseFile);
            InputStream istream = null;
            try {
                istream = new FileInputStream(licenseFile);
                if (!(this.checkLicense.check(istream)))
                    throw new RuntimeException("License .");
            } finally {
                IOUtils.closeQuietly(istream);
            }
            IOUtils.closeQuietly(istream);

            File licensePath = licenseFile.getParentFile();
            if (licensePath.isDirectory()) {
                File[] files = licensePath.listFiles();
                for (File f : files) {
                    if ((!(f.isFile())) || (f.equals(licenseFile)))
                        continue;
                    f.delete();
                }
            }

            if (!(this.checkLicense.refresh()))
                throw new RuntimeException("License .");
        } catch (Exception ex) {
            log.error(" License : " + ex.getMessage(), ex);
            if (licenseFile.exists()) {
                licenseFile.delete();
            }
            return "{success:false, msg:'" + ex.getMessage() + "'}";
        }
        return "{success:true, msg:' License ?.'}";
    }
    return "{success:false, msg:' License ???.'}";
}

From source file:es.uvigo.ei.sing.adops.datatypes.SingleExperiment.java

@Override
public boolean isClean() {
    if (this.hasResult()) {
        return false;
    } else {//from w  w w .  ja v a 2  s  .  c  o m
        final FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                if (pathname.equals(SingleExperiment.this.getNotesFile())
                        || pathname.equals(SingleExperiment.this.getPropertiesFile())
                        || pathname.equals(SingleExperiment.this.getFastaFile())
                        || pathname.equals(SingleExperiment.this.getNamesFile())) {
                    return false;
                } else if (pathname.equals(SingleExperiment.this.getFilesFolder())) {
                    return pathname.listFiles().length != 0;
                }

                return true;
            }
        };

        return this.getFolder().listFiles(filter).length > 0;
    }
}

From source file:org.jephyr.common.maven.AbstractEnhanceMojo.java

@Override
public final void execute() throws MojoExecutionException {
    initialize();/*from  ww  w .j  a v a 2 s  . c o m*/

    File classesDirectory = getClassesDirectory();
    if (!classesDirectory.isDirectory()) {
        return;
    }

    Path classesPath = classesDirectory.toPath();
    Path outputPath = getOutputDirectory().toPath();

    for (File srcFile : listFiles(classesDirectory, null, true)) {
        Path relativePath = classesPath.relativize(srcFile.toPath());
        File destFile = outputPath.resolve(relativePath).toFile();
        if (srcFile.equals(destFile)) {
            if (shouldEnhance(separatorsToUnix(relativePath.toString()))) {
                enhance(srcFile, destFile);
            }
        } else if (srcFile.lastModified() > destFile.lastModified()) {
            if (shouldEnhance(separatorsToUnix(relativePath.toString()))) {
                enhance(srcFile, destFile);
            } else {
                try {
                    copyFile(srcFile, destFile);
                } catch (IOException e) {
                    throw new MojoExecutionException("Failed to copy " + srcFile + " to " + destFile, e);
                }
            }
        }
    }
}

From source file:io.fabric8.tooling.archetype.ArchetypeUtils.java

/**
 * Is the file a valid file to copy (excludes files starting with a dot, build output
 * or java/groovy/kotlin/scala source code
 *//*from w  w w. j a v  a  2s.c  o  m*/
public boolean isValidFileToCopy(File projectDir, File src) throws IOException {
    if (isValidSourceFileOrDir(src)) {
        if (src.equals(projectDir)) {
            return true;
        }

        String relative = relativePath(projectDir, src);
        return !sourceCodeDirPaths.contains(relative);
    }
    return false;
}

From source file:org.grails.ide.eclipse.core.wizard.GrailsImportWizardCore.java

private boolean isDefaultProjectLocation(String projectName, File projectDir) {
    IPath workspaceLoc = Platform.getLocation();
    if (workspaceLoc != null) {
        File defaultLoc = new File(workspaceLoc.toFile(), projectName);
        return defaultLoc.equals(projectDir);
    }/*from  ww  w  . ja  va2s . c o  m*/
    return false;
}

From source file:com.parallax.server.blocklyprop.servlets.HelpServlet.java

public boolean isSubDirectory(File base, File child) throws IOException {
    base = base.getCanonicalFile();/*from  w ww  .j a v a  2  s.  co m*/
    child = child.getCanonicalFile();

    File parentFile = child;
    while (parentFile != null) {
        if (base.equals(parentFile)) {
            return true;
        }
        parentFile = parentFile.getParentFile();
    }
    return false;
}

From source file:au.edu.uq.cmm.paul.queue.AbstractQueueFileManager.java

@Override
public FileStatus getFileStatus(File file) {
    Path path = file.toPath();//from   w  ww  . j a  v  a 2s .  co  m
    File parent = path.getParent().toFile();
    if (Files.exists(path)) {
        if (parent.equals(captureDirectory)) {
            if (Files.isSymbolicLink(path)) {
                return FileStatus.CAPTURED_SYMLINK;
            } else {
                return FileStatus.CAPTURED_FILE;
            }
        } else if (parent.equals(archiveDirectory)) {
            if (Files.isSymbolicLink(path)) {
                return FileStatus.ARCHIVED_SYMLINK;
            } else {
                return FileStatus.ARCHIVED_FILE;
            }
        } else {
            return FileStatus.NOT_OURS;
        }
    } else {
        if (Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {
            if (parent.equals(captureDirectory)) {
                return FileStatus.BROKEN_CAPTURED_SYMLINK;
            } else if (parent.equals(archiveDirectory)) {
                return FileStatus.BROKEN_ARCHIVED_SYMLINK;
            } else {
                return FileStatus.NOT_OURS;
            }
        } else {
            return FileStatus.NON_EXISTENT;
        }
    }
}

From source file:es.uvigo.ei.sing.adops.datatypes.SingleExperiment.java

@Override
public void clear() {
    final FileFilter filter = new FileFilter() {
        @Override/*from  www  .  ja  v a 2 s .  co m*/
        public boolean accept(File pathname) {
            return !(pathname.equals(SingleExperiment.this.getNotesFile())
                    || pathname.equals(SingleExperiment.this.getPropertiesFile())
                    || pathname.equals(SingleExperiment.this.getFastaFile())
                    || pathname.equals(SingleExperiment.this.getNamesFile())
                    || pathname.equals(SingleExperiment.this.getFilesFolder()));
        }
    };

    for (File file : this.getFolder().listFiles(filter)) {
        if (file.isFile())
            file.delete();
        else if (file.isDirectory())
            try {
                FileUtils.deleteDirectory(file);
            } catch (IOException e) {
            }
    }

    try {
        FileUtils.cleanDirectory(this.getFilesFolder());
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.result = null;
}

From source file:gov.redhawk.efs.sca.server.internal.FileSystemImpl.java

@Override
public FileInformationType[] list(final String fullPattern) throws FileException, InvalidFileName {
    final int index = fullPattern.lastIndexOf('/');
    final File container;
    if (index > 0) {
        container = new File(this.root, fullPattern.substring(0, index));
    } else {// w w  w.  ja  va 2 s.co m
        container = this.root;
    }

    final String pattern = fullPattern.substring(index + 1, fullPattern.length());

    final String[] fileNames;

    if (pattern.length() == 0) {
        fileNames = new String[] { "" };
    } else {
        fileNames = container.list(new FilenameFilter() {

            @Override
            public boolean accept(final File dir, final String name) {
                if (!dir.equals(container)) {
                    return false;
                }
                return FilenameUtils.wildcardMatch(name, pattern);
            }
        });
    }

    final FileInformationType[] retVal = new FileInformationType[fileNames.length];
    for (int i = 0; i < fileNames.length; i++) {
        final FileInformationType fileInfo = new FileInformationType();
        final File file = new File(container, fileNames[i]);
        fileInfo.name = file.getName();
        fileInfo.size = file.length();
        if (file.isFile()) {
            fileInfo.kind = FileType.PLAIN;
        } else {
            fileInfo.kind = FileType.DIRECTORY;
        }
        final Any any = this.orb.create_any();
        any.insert_ulonglong(file.lastModified() / FileSystemImpl.MILLIS_PER_SEC);
        final DataType modifiedTime = new DataType("MODIFIED_TIME", any);

        fileInfo.fileProperties = new DataType[] { modifiedTime };

        retVal[i] = fileInfo;
    }
    return retVal;
}