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.kuali.kfs.sys.batch.DirectoryNameFileFilter.java

/**
 * //from   w  w  w .j  a v  a 2 s  .  c om
 * @see org.apache.commons.io.filefilter.IOFileFilter#accept(java.io.File, java.lang.String)
 */
public boolean accept(File directory, String fileName) {
    final File file = new File(directory.getName() + File.separator + fileName);
    if (file.isDirectory())
        return true;
    return directory.equals(directoryName);
}

From source file:me.dags.creativeblock.blockpack.FolderBlockPack.java

public String getTabName(File definitions, File file) {
    File f = file;
    while (!f.getParentFile().equals(definitions)) {
        f = f.getParentFile();/*from  www.  j  a  v a2 s .c o m*/
    }
    return f.equals(file) ? "general" : f.getName().toLowerCase();
}

From source file:io.druid.segment.loading.OmniSegmentLoader.java

public void cleanupCacheFiles(File baseFile, File cacheFile) throws IOException {
    if (cacheFile.equals(baseFile)) {
        return;/*from  w w  w  .j a  v  a2s  .c o m*/
    }

    synchronized (lock) {
        log.info("Deleting directory[%s]", cacheFile);
        try {
            FileUtils.deleteDirectory(cacheFile);
        } catch (Exception e) {
            log.error("Unable to remove file[%s]", cacheFile);
        }
    }

    if (cacheFile.getParentFile() != null && cacheFile.getParentFile().listFiles().length == 0) {
        cleanupCacheFiles(baseFile, cacheFile.getParentFile());
    }
}

From source file:net.geoprism.FileMerger.java

public void mergeDirectories(File base, File override, File export) throws IOException {
    if (!export.exists()) {
        export.mkdirs();//from   ww  w.  j  a va2s .c  o m
    }

    if (!export.equals(override)) {
        for (File overrideChild : override.listFiles()) {
            mergeFile(new File(base, overrideChild.getName()), overrideChild,
                    new File(export, overrideChild.getName()));
        }
    }
    if (!export.equals(base)) {
        for (File baseChild : base.listFiles()) {
            mergeFile(baseChild, new File(override, baseChild.getName()),
                    new File(export, baseChild.getName()));
        }
    }
}

From source file:net.geoprism.FileMerger.java

public void mergeFile(File base, File override, File export) throws IOException {
    if (base == null || !base.exists()) {
        if (!override.equals(export)) {
            if (override.isDirectory()) {
                mergeDirectories(base, override, export);
            } else {
                FileUtils.copyFile(override, export);
            }// w w  w  .  ja  v a 2s .co m
        }
    } else if (override == null || !override.exists()) {
        if (!base.equals(export)) {
            if (base.isDirectory()) {
                mergeDirectories(base, override, export);
            } else {
                FileUtils.copyFile(base, export);
            }
        }
    } else {
        if (override.isDirectory()) {
            mergeDirectories(base, override, export);
        } else if (override.getName().endsWith(".properties")) {
            mergeProperties(base, override, export);
        } else if (!override.equals(export)) {
            FileUtils.copyFile(override, export);
        }
    }
}

From source file:com.appspresso.api.fs.DefaultFileSystem.java

/**
 * File?  DefaultFile? ? ./*  www .  j  av  a  2 s . c  om*/
 * 
 * @param peer File ?
 * @return File?  DefaultFile
 * @since 1.0
 */
protected synchronized DefaultFile createDefaultFile(File peer) {
    if (peer.equals(rootAxFile.getPeer()))
        return (DefaultFile) rootAxFile;

    String cacheKey = peer.getAbsolutePath();
    DefaultFile axFile = cache.get(cacheKey);
    if (null != axFile)
        return axFile;

    DefaultFile parent = createDefaultFile(peer.getParentFile()); // Warning!
                                                                  // Recursive
                                                                  // call.
    axFile = new DefaultFile(this, parent, peer);

    cache.put(cacheKey, axFile);
    return axFile;
}

From source file:net.sourceforge.docfetcher.CommandLineHandler.java

/**
 * Handles command line text extraction. Returns false if the program should
 * terminate after executing this method, and returns true if the program is
 * allowed to proceed.//  w  ww.  j  ava  2  s . c om
 */
private static boolean handleTextExtraction(CommandLine line) {
    if (!line.hasOption(EXTRACT) && !line.hasOption(EXTRACT_DIR))
        return true;

    // Create inclusion and exclusion filters
    Pattern includeFilter = null;
    Pattern excludeFilter = null;
    try {
        String includeString = line.getOptionValue(INCLUDE); // may be null
        includeFilter = Pattern.compile(includeString);
    } catch (Exception e1) {
        // Ignore
    }
    try {
        String excludeString = line.getOptionValue(EXCLUDE); // may be null
        excludeFilter = Pattern.compile(excludeString);
    } catch (Exception e1) {
        // Ignore
    }

    // Get sources and destination
    boolean writeToDir = false;
    String[] args1 = null;
    if (line.hasOption(EXTRACT)) {
        args1 = line.getOptionValues(EXTRACT);
    } else {
        writeToDir = true;
        args1 = line.getOptionValues(EXTRACT_DIR);
    }
    if (args1 == null)
        args1 = new String[0];
    String[] args2 = line.getArgs();
    String[] args = UtilList.concatenate(args1, args2, new String[args1.length + args2.length]);
    if (args.length < 2) {
        System.out.println("Text extraction requires at least one source and one destination.");
        return false;
    }

    // Create source file objects, check for existence
    int lastIndex = args.length - 1;
    File[] topLevelSources = new File[lastIndex];
    for (int i = 0; i < topLevelSources.length; i++) {
        String path = args[i];
        File file = new File(path);
        if (!file.exists()) {
            System.out.println("File not found: " + path);
            return false;
        }
        topLevelSources[i] = file;
    }

    // Check validity of destination
    File dest = new File(args[lastIndex]);
    if (writeToDir) {
        if (dest.exists()) {
            if (!dest.isDirectory()) {
                System.out.println("Not a directory: " + dest.getAbsolutePath());
                return false;
            }
        } else {
            if (!dest.mkdirs()) {
                System.out.println("Could not create directory: " + dest.getAbsolutePath());
                return false;
            }
        }
    }

    /*
     * The source files are collected beforehand because
     * 1) the text output will depend on the number of files to process,
     * so we first have to determine how many files there are
     * 2) the target file(s) might lie inside one of the source directories,
     * so we first collect all source files in order to avoid confusion
     * 3) by using a Map, we make sure there aren't any duplicate sources.
     */
    Map<File, Parser> sources = new LinkedHashMap<File, Parser>();
    for (File topLevelSource : topLevelSources)
        collect(topLevelSource, sources, includeFilter, excludeFilter, true);
    int nSources = sources.size(); // must be set *after* filling the sources list!

    // Perform text extraction
    if (writeToDir) {
        int i = 1;
        for (Entry<File, Parser> item : sources.entrySet()) {
            File source = item.getKey();
            System.out.println("Extracting (" + i + "/" + nSources + "): " + source.getName());
            try {
                File outFile = UtilFile.getNewFile(dest, source.getName() + ".txt");
                String text = item.getValue().renderText(source);
                FileWriter writer = new FileWriter(outFile, false);
                writer.write(text);
                writer.close();
            } catch (Exception e) {
                System.out.println("  Error: " + e.getMessage());
            }
            i++;
        }
    } else {
        // First check that the destination is not one of the source files
        for (File source : sources.keySet()) {
            if (source.equals(dest)) {
                System.out.println("Invalid input: Destination is identical to one of the source files.");
                return false;
            }
        }
        // If there's only one file to process, don't decorate the text output
        if (nSources == 1) {
            Entry<File, Parser> item = sources.entrySet().iterator().next();
            System.out.println("Extracting: " + item.getKey().getName());
            try {
                String text = item.getValue().renderText(item.getKey());
                FileWriter writer = new FileWriter(dest);
                writer.write(text);
                writer.close();
            } catch (Exception e) {
                System.out.println("  Error: " + e.getMessage());
            }
        }
        // Multiple files to process:
        else {
            try {
                FileWriter writer = new FileWriter(dest, false); // overwrite
                int i = 1;
                for (Entry<File, Parser> item : sources.entrySet()) {
                    File source = item.getKey();
                    System.out.println("Extracting (" + i + "/" + nSources + "): " + source.getName());
                    try {
                        String text = item.getValue().renderText(source); // This may fail, so do it first
                        writer.write("Source: " + source.getAbsolutePath() + Const.LS);
                        writer.write("============================================================" + Const.LS);
                        writer.write(text);
                        writer.write(Const.LS + Const.LS + Const.LS);
                    } catch (Exception e) {
                        System.out.println("  Error: " + e.getMessage());
                    }
                    i++;
                }
                writer.close();
            } catch (IOException e) {
                System.out.println("Can't write to file: " + e.getMessage());
            }
        }
    }
    return false;
}

From source file:org.geoserver.importer.SpatialFile.java

@Override
public void prepare(ProgressMonitor m) throws IOException {
    //round up all the files with the same name
    suppFiles = new ArrayList();
    prjFile = null;//w  ww .j  a  va2  s.c om

    // getBaseName only gets the LAST extension so beware for .shp.aux.xml stuff
    final String baseName = getBaseName(file.getName());

    for (File f : file.getParentFile().listFiles()) {
        if (f.equals(file)) {
            continue;
        }

        if (!f.getName().startsWith(baseName)) {
            continue;
        }

        if (!f.isFile()) {
            continue;
        }

        String ext = f.getName().substring(baseName.length());
        // once the basename is stripped, extension(s) should be present
        if (ext.charAt(0) == '.') {
            if (".prj".equalsIgnoreCase(ext)) {
                prjFile = f;
            } else {
                suppFiles.add(f);
            }
        }
    }
    if (format == null) {
        format = DataFormat.lookup(file);
    }

    //fix the prj file (match to official epsg wkt)
    try {
        fixPrjFile();
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error fixing prj file", e);
    }
}

From source file:com.p2p.peercds.common.Torrent.java

private static void updateFileInfo(List<File> filesList, File parent, File actualParent, List<BEValue> fileInfo,
        List<File> files) throws UnsupportedEncodingException {

    for (File file : filesList) {
        if (!file.isDirectory()) {
            Map<String, BEValue> fileMap = new HashMap<String, BEValue>();
            fileMap.put("length", new BEValue(file.length()));

            LinkedList<BEValue> filePath = new LinkedList<BEValue>();
            File actual = file;/* www.  j a  va  2  s.  c  om*/
            while (file != null) {
                if (file.equals(actualParent)) {
                    break;
                }

                filePath.addFirst(new BEValue(file.getName()));
                file = file.getParentFile();
            }

            fileMap.put("path", new BEValue(filePath));
            fileInfo.add(new BEValue(fileMap));
            logger.info("adding file: " + actual.getName() + " to the files list");
            files.add(actual);
        } else {
            logger.info("Making recursive call");
            updateFileInfo(Arrays.asList(file.listFiles(Constants.hiddenFilesFilter)), file, actualParent,
                    fileInfo, files);
        }
    }
}

From source file:nl.opengeogroep.filesetsync.server.stripes.FilesetBaseActionBean.java

@ValidationMethod
public void checkFileset() throws IOException {

    if (fileset == null) {
        getContext().getValidationErrors()
                .addGlobalError(new SimpleError("Fileset path not found: " + filesetPath));
        return;/*from   www.java  2 s .co m*/
    }

    File filesetRoot = new File(fileset.getPath());
    if (!filesetRoot.exists()) {
        log.error("local path does not exist for requested fileset path " + filesetPath + ": "
                + fileset.getPath());
        getContext().getValidationErrors()
                .addGlobalError(new SimpleError("Fileset does not exist on server: " + filesetPath));
        return;
    }

    // Check if subPath does not navigate with .. outside of fileset path
    // Note that .. may be stripped from HttpServletRequest.getPathInfo()
    // but Stripes also supports GET /filesetsync-server/fileset/list?filesetPath=/some/../../secret/file
    if (subPath.length() != 0) {
        if (!filesetRoot.isDirectory()) {
            getContext().getValidationErrors()
                    .addGlobalError(new SimpleError("Fileset path does not exist: " + filesetPath));
            return;
        }
        File subFile = new File(fileset.getPath() + subPath);
        subFile = subFile.getCanonicalFile();
        if (!subFile.exists()) {
            getContext().getValidationErrors()
                    .addGlobalError(new SimpleError("Fileset path does not exist: " + filesetPath));
            return;
        }

        filesetRoot = filesetRoot.getCanonicalFile();

        File parent = subFile;
        while (parent != null && !parent.equals(filesetRoot)) {
            parent = parent.getParentFile();
        }
        if (parent == null) {
            log.info(String.format(
                    "requested fileset path \"%s\" does not exist or is not subdir of fileset root \"%s\"",
                    filesetPath, fileset.getPath()));
            getContext().getValidationErrors()
                    .addGlobalError(new SimpleError("Fileset path does not exist: " + filesetPath));
            return;
        }
    }
}