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:eu.stratosphere.test.util.AbstractTestBase.java

public File createAndRegisterTempFile(String fileName) throws IOException {
    File baseDir = new File(System.getProperty("java.io.tmpdir"));
    File f = new File(baseDir, fileName);

    if (f.exists()) {
        deleteRecursively(f);//  www. jav  a  2  s . co  m
    }

    File parentToDelete = f;
    while (true) {
        File parent = parentToDelete.getParentFile();
        if (parent == null) {
            throw new IOException("Missed temp dir while traversing parents of a temp file.");
        }
        if (parent.equals(baseDir)) {
            break;
        }
        parentToDelete = parent;
    }

    Files.createParentDirs(f);
    this.tempFiles.add(parentToDelete);
    return f;
}

From source file:org.onebusaway.admin.util.NYCFileUtils.java

public void copyFiles(File from, File to) {
    _log.debug("copying " + from + " to " + to);
    try {/*ww w . ja va2 s  .  com*/
        if (!from.exists())
            return;
        if (from.equals(to) || to.getParent().equals(from))
            return;
        if (to.exists() && to.isDirectory()) {
            if (from.exists() && from.isDirectory()) {
                org.apache.commons.io.FileUtils.copyDirectory(from, to, true);
                return; // Added to prevent dupe dir.  JP 10/14/15
            }
            String file = this.parseFileName(from.toString());
            to = new File(to.toString() + File.separator + file);
            _log.debug("constructed new destination=" + to.toString());
        }

        if (from.isDirectory()) {
            to.mkdirs();
            File[] files = from.listFiles();
            if (files == null)
                return;
            for (File fromChild : files) {
                File toChild = new File(to, fromChild.getName());
                copyFiles(fromChild, toChild);
            }
        } else {
            org.apache.commons.io.FileUtils.copyFile(from, to, true/*preserve date*/);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

}

From source file:org.opendatakit.utilities.ODKFileUtils.java

/**
 * Used in services.preferences.fragments.DeviceSettingsFragment
 *
 * @param appName the app name/*from   w  ww .  j a va 2s  . c  om*/
 * @param path    the path to check against
 * @return whether the path is under :app_name/
 */
@SuppressWarnings("unused")
public static boolean isPathUnderAppName(String appName, File path) {

    File parentDir = new File(getAppFolder(appName));

    while (path != null && !path.equals(parentDir)) {
        path = path.getParentFile();
    }

    return path != null;
}

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

@Override
public DataSegment push(File dataSegmentFile, DataSegment segment) throws IOException {
    final String storageDir = this.getStorageDir(segment);
    final File baseStorageDir = config.getStorageDirectory();
    final File outDir = new File(baseStorageDir, storageDir);

    log.info("Copying segment[%s] to local filesystem at location[%s]", segment.getIdentifier(),
            outDir.toString());//from  w w w.  j ava 2s.c om

    if (dataSegmentFile.equals(outDir)) {
        long size = 0;
        for (File file : dataSegmentFile.listFiles()) {
            size += file.length();
        }

        return createDescriptorFile(segment.withLoadSpec(makeLoadSpec(outDir.toURI())).withSize(size)
                .withBinaryVersion(SegmentUtils.getVersionFromDir(dataSegmentFile)), outDir);
    }

    final File tmpOutDir = new File(baseStorageDir, intermediateDirFor(storageDir));
    log.info("Creating intermediate directory[%s] for segment[%s]", tmpOutDir.toString(),
            segment.getIdentifier());
    final long size = compressSegment(dataSegmentFile, tmpOutDir);

    final DataSegment dataSegment = createDescriptorFile(
            segment.withLoadSpec(makeLoadSpec(new File(outDir, "index.zip").toURI())).withSize(size)
                    .withBinaryVersion(SegmentUtils.getVersionFromDir(dataSegmentFile)),
            tmpOutDir);

    // moving the temporary directory to the final destination, once success the potentially concurrent push operations
    // will be failed and will read the descriptor.json created by current push operation directly
    FileUtils.forceMkdir(outDir.getParentFile());
    try {
        Files.move(tmpOutDir.toPath(), outDir.toPath());
    } catch (FileAlreadyExistsException e) {
        log.warn("Push destination directory[%s] exists, ignore this message if replication is configured.",
                outDir);
        FileUtils.deleteDirectory(tmpOutDir);
        return jsonMapper.readValue(new File(outDir, "descriptor.json"), DataSegment.class);
    }
    return dataSegment;
}

From source file:org.codelibs.fess.app.web.admin.design.AdminDesignAction.java

private OptionalEntity<File> getTargetFile(final String fileName) {
    final File baseDir = new File(getServletContext().getRealPath("/"));
    final File targetFile = new File(getServletContext().getRealPath(fileName));
    final List<File> fileList = getAccessibleFileList(baseDir);
    for (final File file : fileList) {
        if (targetFile.equals(file)) {
            return OptionalEntity.of(targetFile);
        }/*from  w  w w  . j a  va2  s  .c  om*/
    }
    return OptionalEntity.empty();
}

From source file:org.codelibs.fess.web.admin.DesignAction.java

private File getTargetFile() {
    final File baseDir = new File(ServletContextUtil.getServletContext().getRealPath("/"));
    final File targetFile = new File(ServletContextUtil.getServletContext().getRealPath(designForm.fileName));
    final List<File> fileList = getAccessibleFileList(baseDir);
    boolean exist = false;
    for (final File file : fileList) {
        if (targetFile.equals(file)) {
            exist = true;/*w w w. j ava  2 s.c  o  m*/
            break;
        }
    }
    if (exist) {
        return targetFile;
    }
    return null;
}

From source file:org.apache.openmeetings.backup.BackupExport.java

private void writeZipDir(URI base, File dir, ZipOutputStream zos, File zipFile) throws IOException {
    for (File file : dir.listFiles()) {
        if (zipFile.equals(file)) {
            continue;
        }/*from   w w  w  .j  av a 2s .  com*/
        if (file.isDirectory()) {
            writeZipDir(base, file, zos, zipFile);
        } else {
            String path = base.relativize(file.toURI()).toString();
            log.debug("Writing '" + path + "' to zip file");
            ZipEntry zipEntry = new ZipEntry(path);
            zos.putNextEntry(zipEntry);

            OmFileHelper.copyFile(file, zos);
            zos.closeEntry();
        }
    }
}

From source file:com.adamrosenfield.wordswithcrosses.versions.DefaultUtil.java

public void downloadFile(URL url, Map<String, String> headers, File destination, boolean notification,
        String title, HttpContext httpContext) throws IOException {
    String scrubbedUrl = AbstractDownloader.scrubUrl(url);
    File tempFile = new File(WordsWithCrossesApplication.TEMP_DIR, destination.getName());
    LOG.info("DefaultUtil: Downloading " + scrubbedUrl + " ==> " + tempFile);
    FileOutputStream fos = new FileOutputStream(tempFile);
    try {/* w ww.j a v a2s. c  om*/
        downloadHelper(url, scrubbedUrl, headers, httpContext, fos);
    } finally {
        fos.close();
    }

    if (!tempFile.equals(destination) && !tempFile.renameTo(destination)) {
        throw new IOException("Failed to rename " + tempFile + " to " + destination);
    }

    LOG.info("DefaultUtil: Download succeeded: " + scrubbedUrl);
}

From source file:org.opendatakit.utilities.ODKFileUtils.java

/**
 * Used in AggregateSynchronizer, services.sync.logic.ProcessManifestContentAndFileChanges
 *
 * @param path the path that's under an app
 * @return the app name/*from  w ww. j  ava  2  s  .c  o m*/
 */
@SuppressWarnings("unused")
public static String extractAppNameFromPath(File path) {
    if (path == null) {
        return null;
    }

    File parent = path.getParentFile();
    File odkDir = new File(getOdkFolder());
    while (parent != null && !parent.equals(odkDir)) {
        path = parent;
        parent = path.getParentFile();
    }

    if (parent == null) {
        return null;
    }
    return path.getName();
}

From source file:com.haw3d.jadvalKalemat.versions.DefaultUtil.java

public void downloadFile(URL url, Map<String, String> headers, File destination, boolean notification,
        String title, HttpContext httpContext) throws IOException {
    String scrubbedUrl = AbstractDownloader.scrubUrl(url);
    File tempFile = new File(jadvalKalematApplication.TEMP_DIR, destination.getName());
    LOG.info("DefaultUtil: Downloading " + scrubbedUrl + " ==> " + tempFile);
    FileOutputStream fos = new FileOutputStream(tempFile);
    try {/*w w w . java 2 s. c o m*/
        downloadHelper(url, scrubbedUrl, headers, httpContext, fos);
    } finally {
        fos.close();
    }

    if (!tempFile.equals(destination) && !tempFile.renameTo(destination)) {
        throw new IOException("Failed to rename " + tempFile + " to " + destination);
    }

    LOG.info("DefaultUtil: Download succeeded: " + scrubbedUrl);
}