Example usage for java.io File hashCode

List of usage examples for java.io File hashCode

Introduction

In this page you can find the example usage for java.io File hashCode.

Prototype

public int hashCode() 

Source Link

Document

Computes a hash code for this abstract pathname.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    // create new files
    File f = new File("c:/");

    System.out.print(f.hashCode());

}

From source file:Main.java

public static String setHashValue(String path) {
    File f = new File(path);
    String result = String.valueOf(f.hashCode());

    return result;
}

From source file:com.norconex.committer.core.FileAddOperation.java

/**
 * Constructor./*from w  w w  . j av  a2  s.c  om*/
 * @param refFile the reference file to be added
 */
public FileAddOperation(File refFile) {
    super();
    this.hashCode = refFile.hashCode();
    this.refFile = refFile;

    String basePath = StringUtils.removeEnd(refFile.getAbsolutePath(), FileSystemCommitter.EXTENSION_REFERENCE);
    this.contentFile = new File(basePath + FileSystemCommitter.EXTENSION_CONTENT);
    this.metaFile = new File(basePath + FileSystemCommitter.EXTENSION_METADATA);
    try {
        this.reference = FileUtils.readFileToString(refFile, CharEncoding.UTF_8);
    } catch (IOException e) {
        throw new CommitterException("Could not load reference for " + refFile, e);
    }
    this.metadata = new Properties();
    synchronized (metadata) {
        if (metaFile.exists()) {
            FileInputStream is = null;
            try {
                is = new FileInputStream(metaFile);
                metadata.load(is);
            } catch (IOException e) {
                throw new CommitterException("Could not load metadata for " + metaFile, e);
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }

}

From source file:com.ning.maven.plugins.duplicatefinder.DuplicateFinderMojo.java

/**
 * Calculates the SHA256 Hash of a class in a file.
 * //ww  w . ja  v a 2  s  .c o  m
 * @param file the archive contains the class
 * @param resourcePath the name of the class
 * @return the MD% Hash as Hex-Value
 * @throws IOException if any error occurs on reading class in archive
 */
private String getSHA256HexOfElement(final File file, final String resourcePath) throws IOException {
    class Sha256CacheKey {
        final File file;
        final String resourcePath;

        Sha256CacheKey(File file, String resourcePath) {
            this.file = file;
            this.resourcePath = resourcePath;
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;

            Sha256CacheKey key = (Sha256CacheKey) o;

            return file.equals(key.file) && resourcePath.equals(key.resourcePath);
        }

        public int hashCode() {
            return 31 * file.hashCode() + resourcePath.hashCode();
        }
    }

    final Sha256CacheKey key = new Sha256CacheKey(file, resourcePath);
    if (CACHED_SHA256.containsKey(key)) {
        return (String) CACHED_SHA256.get(key);
    }

    ZipFile zip = new ZipFile(file);
    ZipEntry zipEntry = zip.getEntry(resourcePath);
    if (zipEntry == null) {
        throw new IOException("Could not found Zip-Entry for " + resourcePath + " in file " + file);
    }

    String sha256;

    InputStream in = zip.getInputStream(zipEntry);
    try {
        sha256 = DigestUtils.sha256Hex(in);
    } finally {
        IOUtils.closeQuietly(in);
    }

    CACHED_SHA256.put(key, sha256);

    return sha256;
}

From source file:org.syncany.tests.integration.scenarios.framework.MoveFolderWithinFolder.java

@Override
public void execute() throws Exception {
    File fromFolder = pickFolder(3123);
    File toFolder = new File(fromFolder + "-ren" + fromFolder.hashCode());

    log(this, fromFolder + " -> " + toFolder);
    FileUtils.moveDirectory(fromFolder, toFolder);
}

From source file:play.modules.netty.PlayHandler.java

private static HttpResponse addEtag(HttpRequest nettyRequest, HttpResponse httpResponse, File file) {
    if (Play.mode == Play.Mode.DEV) {
        httpResponse.setHeader(CACHE_CONTROL, "no-cache");
    } else {/*from  www.ja  va  2 s  .c o m*/
        String maxAge = Play.configuration.getProperty("http.cacheControl", "3600");
        if (maxAge.equals("0")) {
            httpResponse.setHeader(CACHE_CONTROL, "no-cache");
        } else {
            httpResponse.setHeader(CACHE_CONTROL, "max-age=" + maxAge);
        }
    }
    boolean useEtag = Play.configuration.getProperty("http.useETag", "true").equals("true");
    long last = file.lastModified();
    final String etag = "\"" + last + "-" + file.hashCode() + "\"";
    if (!isModified(etag, last, nettyRequest)) {
        if (nettyRequest.getMethod().equals(HttpMethod.GET)) {
            httpResponse.setStatus(HttpResponseStatus.NOT_MODIFIED);
        }
        if (useEtag) {
            httpResponse.setHeader(ETAG, etag);
        }

    } else {
        httpResponse.setHeader(LAST_MODIFIED, Utils.getHttpDateFormatter().format(new Date(last)));
        if (useEtag) {
            httpResponse.setHeader(ETAG, etag);
        }
    }
    return httpResponse;
}

From source file:swift.application.filesystem.fuse.FilesystemFuse.java

@Override
public int getattr(String path, FuseGetattrSetter getattrSetter) throws FuseException {
    String remotePath = getRemotePath(path);
    File fstub = new File(remotePath);
    log.info("getattr for " + remotePath);
    int time = (int) (System.currentTimeMillis() / 1000L);
    synchronized (this) {
        TxnHandle txn = null;//from   ww w. ja  va 2s.c o  m
        try {
            txn = server.beginTxn(isolationlevel, cachepolicy, true);
            if ("/".equals(path)) {
                DirectoryCRDT root = fs.getDirectory(txn, "/" + ROOT);
                getattrSetter.set(root.hashCode(), FuseFtypeConstants.TYPE_DIR | MODE, 1, 0, 0, 0,
                        root.getValue().size() * NAME_LENGTH,
                        (root.getValue().size() * NAME_LENGTH + BLOCK_SIZE - 1) / BLOCK_SIZE, time, time, time);
            } else if (fs.isDirectory(txn, fstub.getName(), fstub.getParent())) {
                DirectoryCRDT dir = fs.getDirectory(txn, remotePath);
                getattrSetter.set(dir.hashCode(), FuseFtypeConstants.TYPE_DIR | MODE, 1, 0, 0, 0,
                        dir.getValue().size() * NAME_LENGTH,
                        (dir.getValue().size() * NAME_LENGTH + BLOCK_SIZE - 1) / BLOCK_SIZE, time, time, time);
            } else if (fs.isFile(txn, fstub.getName(), fstub.getParent())) {
                IFile f = fs.readFile(txn, fstub.getName(), fstub.getParent());
                getattrSetter.set(fstub.hashCode(), FuseFtypeConstants.TYPE_FILE | MODE, 1, 0, 0, 0,
                        f.getSize(), (f.getSize() + BLOCK_SIZE - 1) / BLOCK_SIZE, time, time, time);
            } else {
                txn.rollback();
                return Errno.ENOENT;
            }
            commit(txn);
            return 0;

        } catch (NetworkException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (WrongTypeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchObjectException e) {
            e.printStackTrace();
        } catch (VersionNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        txn.rollback();
    }
    return Errno.ENOENT;

}