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:com.amazonaws.eclipse.core.accounts.profiles.SdkCredentialsFileContentMonitor.java

public SdkCredentialsFileContentMonitor(File target, long pollingIntervalInMillis,
        FileAlterationListener listener) {

    _target = target;/* w ww .  j  ava  2s.c o m*/

    // IllegalArgumentException is expected if target.getParentFile == null
    _observer = new FileAlterationObserver(target.getParentFile(), new FileFilter() {
        public boolean accept(File file) {
            return file.equals(_target);
        }
    });

    _monitor = new FileAlterationMonitor(pollingIntervalInMillis);
    _listener = listener;

    _observer.addListener(_listener);
    _monitor.addObserver(_observer);

    // Use daemon thread to avoid thread leakage
    _monitor.setThreadFactory(new ThreadFactory() {
        public Thread newThread(Runnable runnable) {
            Thread t = new Thread(runnable);
            t.setDaemon(true);
            t.setName("aws-credentials-file-monitor-thread");
            return t;
        }
    });
}

From source file:net.technicpack.autoupdate.tasks.MoveLauncherPackage.java

@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
    String currentPath = relauncher.getRunningPath();
    Utils.getLogger().log(Level.INFO,
            "Moving running package from " + currentPath + " to " + launcher.getAbsolutePath());

    File source = new File(currentPath);
    File dest = new File(launcher.getAbsolutePath());

    if (!source.equals(dest)) {
        if (dest.exists()) {
            if (!dest.delete())
                Utils.getLogger().log(Level.SEVERE, "Deletion of existing package failed!");
        }/*from  w  ww.  j a  va 2s. c o m*/
        FileInputStream sourceStream = null;
        FileOutputStream destStream = null;

        try {
            if (!dest.getParentFile().exists())
                dest.getParentFile().mkdirs();
            dest.createNewFile();
            sourceStream = new FileInputStream(source);
            destStream = new FileOutputStream(dest);
            IOUtils.copy(sourceStream, destStream);
        } catch (IOException ex) {
            Utils.getLogger().log(Level.SEVERE, "Error attempting to copy download package:", ex);
        } finally {
            IOUtils.closeQuietly(sourceStream);
            IOUtils.closeQuietly(destStream);
        }
    }

    dest.setExecutable(true, true);
}

From source file:org.qedeq.base.io.IoUtility.java

/**
 * Create relative address from <code>origin</code> to <code>next</code>.
 * The resulting file path has "/" as directory name separator.
 * If the resulting file path is the same as origin specifies, we return "".
 * Otherwise the result will always have an "/" as last character.
 *
 * @param   origin  This is the original location. Must be a directory.
 * @param   next    This should be the next location. Must also be a directory.
 * @return  Relative (or if necessary absolute) file path.
 *//*from   w  ww.j  ava 2s.c  o  m*/
public static final String createRelativePath(final File origin, final File next) {
    if (origin.equals(next)) {
        return "";
    }
    final Path org = new Path(origin.getPath().replace(File.separatorChar, '/'), "");
    final Path ne = new Path(next.getPath().replace(File.separatorChar, '/'), "");
    return org.createRelative(ne.toString()).toString();
}

From source file:name.martingeisse.webide.features.java.compiler.classpath.ClassFolderLibraryFileManager.java

/**
 * Infers the package prefix (package name followed by a dot except if it is the default package) of the
 * specified package folder, or null if not a package folder in this file manager.
 *//*from w w  w .  j a  v a  2 s .  c  o  m*/
private String inferPackagePrefix(File folder) {
    if (folder.equals(this.canonicalFolder)) {
        return "";
    }
    if (folder.getParentFile() == null) {
        return null;
    }
    String parent = inferPackagePrefix(folder.getParentFile());
    if (parent == null) {
        return null;
    }
    return (parent.isEmpty() ? folder.getName() : (parent + folder.getName())) + '.';
}

From source file:de.qucosa.webapi.v1.FileHandlingService.java

public URI renameFileInTargetFileSpace(String filename, String newname, String qid) throws IOException {
    File sourceFile = new File(new File(documentsPath, qid), filename);
    File targetFile = new File(new File(documentsPath, qid), newname);
    if (!sourceFile.equals(targetFile)) {
        FileUtils.moveFile(sourceFile, targetFile);
    }// w  ww.j a va2s . c  o m
    return targetFile.toURI().normalize();
}

From source file:org.ops4j.pax.runner.platform.internal.RelativeFilePathStrategy.java

/**
 * Here we finally decide on actual paths showing up in generated config files and commandline args.
 *
 * @param baseFolder folder to be used. This is what we will cut off.
 * @param file       to be normalized./*w w w  .j a va 2  s .  c o m*/
 *
 * @return if file is a child of base then we will return the relative path. If not, the full path of file will be returned.
 */
private String normalizePath(final File baseFolder, final File file) {
    String out = file.getAbsolutePath();
    try {
        if (baseFolder.equals(file)) {
            out = ".";
        } else {
            String s1 = baseFolder.getCanonicalPath();
            String s2 = file.getCanonicalPath();
            if (s2.startsWith(s1)) {
                out = s2.substring(s1.length() + 1);
            } else {
                out = s2;
            }
        }
    } catch (IOException e) {
        LOG.warn("problem during normalizing path.", e);
    }
    return out.replace(File.separatorChar, '/');
}

From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileLocationProvider.java

/**
 * @see ArchiveFileLocationProvider#getChildPathRelativeToParent(java.io.File, java.lang.String)
 *//* w  ww .  j a va  2  s  .c o  m*/
@Override
public String getChildPathRelativeToParent(File parentNodeFile, File childNodeFile) {

    if (parentNodeFile.equals(childNodeFile)) {
        throw new IllegalStateException("Parent and child files should be different");
    }

    String parentDirectory = FilenameUtils.getFullPath(parentNodeFile.getAbsolutePath());
    Path parentDirPath = Paths.get(parentDirectory);
    Path childFilePath = Paths.get(childNodeFile.getAbsolutePath());
    Path relativePath = parentDirPath.relativize(childFilePath);

    return relativePath.toString();
}

From source file:org.dbgl.util.FileUtils.java

private static File strip(final File file, final File basePath) {
    if (file.equals(basePath))
        return new File(".");
    File remainder = new File(file.getName());
    File parent = file.getParentFile();
    while (parent != null) {
        if (parent.equals(basePath))
            return remainder;
        remainder = new File(parent.getName(), remainder.getPath());
        parent = parent.getParentFile();
    }/*  ww w  .  j  a v  a 2 s .  c  o m*/
    return file;
}

From source file:com.sqli.liferay.imex.util.xml.ZipUtils.java

private void zipEntries(ZipOutputStream out, File file, File inputDir) throws IOException {
    String name;//ww w  . ja v a  2 s.  c o m
    if (file.equals(inputDir)) {
        name = "";
    } else {
        name = file.getPath().substring(inputDir.getPath().length() + 1);
    }
    if (File.separatorChar == '\\') {
        name = name.replace("\\", "/");
    }

    log.debug("Adding: " + name);

    if (file.isDirectory()) {
        for (File child : file.listFiles()) {
            zipEntries(out, child, inputDir);
        }
    } else {
        ZipEntry entry = new ZipEntry(name);
        out.putNextEntry(entry);
        IOUtils.copy(FileUtils.openInputStream(file), out);
    }
}

From source file:org.bitstrings.maven.plugins.indexer.IndexerMojo.java

private void createIndexFile(String indexFileName, String charset, File directory, List<String> includes,
        List<String> excludes, boolean recursive) throws MojoExecutionException {
    final Collection<File> files = FileUtils.listFilesAndDirs(directory,
            FileFilterUtils.and(new WildcardFileFilter(includes),
                    FileFilterUtils.notFileFilter(new WildcardFileFilter(excludes))),
            (recursive ? TrueFileFilter.INSTANCE : null));

    final File indexFile = new File(directory, indexFileName);

    final List<File> directories = Lists.newArrayList();

    // FIXME: charset
    try (BufferedWriter writer = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(indexFile), charset))) {
        if (!quiet) {
            getLog().info("Writing index for [ " + indexFile + " ].");
        }/*from  w ww. j a v  a 2  s  . c  o m*/

        for (File file : files) {
            if (file.equals(directory) || file.getName().equals(indexFileName)) {
                continue;
            }

            final StringBuilder sb = new StringBuilder();

            if (file.isDirectory()) {
                sb.append("D");
                directories.add(file);
            } else {
                sb.append("F");
            }

            sb.append(",");
            sb.append(file.getName());

            writer.write(sb.toString());
            writer.newLine();
        }
    } catch (Exception e) {
        throw new MojoExecutionException(e.getLocalizedMessage(), e);
    }

    if (recursive) {
        for (File dir : directories) {
            createIndexFile(indexFileName, charset, dir, includes, excludes, recursive);
        }
    }
}