Package com.google.common.hash

Examples of com.google.common.hash.Hasher


     *
     * @param l the literal to create the hash for
     * @return a 64bit hash key for the literal
     */
    public static String createCacheKey(Literal l) {
        Hasher hasher = Hashing.goodFastHash(64).newHasher();
        hasher.putString(l.getLabel(), Charset.defaultCharset());
        if(l.getDatatype() != null) {
            hasher.putString(l.getDatatype().stringValue(), Charset.defaultCharset());
        }
        if(l.getLanguage() != null) {
            hasher.putString(l.getLanguage().toLowerCase(), Charset.defaultCharset());
        }
        return hasher.hash().toString();
    }
View Full Code Here


    }
   
    public static String getETag(RepositoryConnection conn, URI resource) throws RepositoryException {
      if (resource == null) return "";
     
        Hasher hasher = buildHasher();
        hasher.putString(resource.stringValue(), Charset.defaultCharset());
        //FIXME: The order of the statements is not defined -> might result in different hash!
        RepositoryResult<Statement> outgoing = conn.getStatements(resource, null, null, true);
        try {
          while (outgoing.hasNext()) {
            Statement statement = outgoing.next();
            hasher.putString(statement.getPredicate().stringValue(), Charset.defaultCharset());
              hasher.putString(statement.getObject().stringValue(), Charset.defaultCharset());
              //TODO: statement modification date?
          }
        } finally {
          outgoing.close();
        }
        RepositoryResult<Statement> incoming = conn.getStatements(null, null, resource, true);
        try {
          while (incoming.hasNext()) {
            Statement statement = incoming.next();
            hasher.putString(statement.getSubject().stringValue(), Charset.defaultCharset());
            hasher.putString(statement.getPredicate().stringValue(), Charset.defaultCharset());
            //TODO: statement modification date?
          }   
        } finally {
          incoming.close();
        }
        return hasher.hash().toString();
    }
View Full Code Here

//    }
   
    public static String getWeakETag(RepositoryConnection conn, Resource resource) throws RepositoryException {
      if (resource == null) return "";
     
        Hasher hasher = buildHasher();
        hasher.putString(resource.stringValue(), Charset.defaultCharset());
        //FIXME: The order of the statements is not defined -> might result in different hash!
        RepositoryResult<Statement> statements = conn.getStatements(resource, null, null, true);
        try {
          while (statements.hasNext()) {
            Statement statement = statements.next();
            hasher.putString(statement.getPredicate().stringValue(), Charset.defaultCharset());
            hasher.putString(statement.getObject().stringValue(), Charset.defaultCharset());
            //TODO: statement modification date?
          }
        } finally {
          statements.close();
        }
        return hasher.hash().toString();
    }
View Full Code Here

        return hasher.hash().toString();
    }

    private static Hasher buildHasher() {
        HashFunction function = Hashing.goodFastHash(16);
        Hasher hasher = function.newHasher();
        return hasher;
    }
View Full Code Here

    }

    @Override
    public String write(InputStream in) throws MicroKernelException {
        try {
            final Hasher hasher = Hashing.sha256().newHasher();
            Blob blob = store.createBlob(
                    new CheckedInputStream(in, new Checksum() {
                        @Override
                        public void update(byte[] b, int off, int len) {
                            hasher.putBytes(b, off, len);
                        }
                        @Override
                        public void update(int b) {
                            hasher.putByte((byte) b);
                        }
                        @Override
                        public void reset() {
                            throw new UnsupportedOperationException();
                        }
                        @Override
                        public long getValue() {
                            throw new UnsupportedOperationException();
                        }
                    }));
            HashCode hash = hasher.hash();

            // wrap into AbstractBlob for the SHA-256 memorization feature
            if (!(blob instanceof AbstractBlob)) {
                final Blob b = blob;
                blob = new AbstractBlob(hash) {
View Full Code Here

     * @param language language of the literal (optional)
     * @param type     datatype URI of the literal (optional)
     * @return a 64bit hash key for the literal
     */
    public static String createCacheKey(String content, Locale language, String type) {
        Hasher hasher = Hashing.goodFastHash(64).newHasher();
        hasher.putString(content);
        if(type != null) {
            hasher.putString(type);
        }
        if(language != null) {
            hasher.putString(language.getLanguage().toLowerCase());
        }
        return hasher.hash().toString();
    }
View Full Code Here

     *
     * @param l the literal to create the hash for
     * @return a 64bit hash key for the literal
     */
    public static String createCacheKey(Literal l) {
        Hasher hasher = Hashing.goodFastHash(64).newHasher();
        hasher.putString(l.getLabel());
        if(l.getDatatype() != null) {
            hasher.putString(l.getDatatype().stringValue());
        }
        if(l.getLanguage() != null) {
            hasher.putString(l.getLanguage().toLowerCase());
        }
        return hasher.hash().toString();
    }
View Full Code Here

    }
   
    public static String getETag(RepositoryConnection conn, URI resource) throws RepositoryException {
      if (resource == null) return "";
     
        Hasher hasher = buildHasher();
        hasher.putString(resource.stringValue());
        //FIXME: The order of the statements is not defined -> might result in different hash!
        RepositoryResult<Statement> outgoing = conn.getStatements(resource, null, null, true);
        try {
          while (outgoing.hasNext()) {
            Statement statement = outgoing.next();
            hasher.putString(statement.getPredicate().stringValue());
              hasher.putString(statement.getObject().stringValue());
              //TODO: statement modification date?
          }
        } finally {
          outgoing.close();
        }
        RepositoryResult<Statement> incoming = conn.getStatements(null, null, resource, true);
        try {
          while (incoming.hasNext()) {
            Statement statement = incoming.next();
            hasher.putString(statement.getSubject().stringValue());
            hasher.putString(statement.getPredicate().stringValue());
            //TODO: statement modification date?
          }   
        } finally {
          incoming.close();
        }
        return hasher.hash().toString();
    }
View Full Code Here

    }  
   
    public static String getWeakETag(RepositoryConnection conn, URI resource) throws RepositoryException {
      if (resource == null) return "";
     
        Hasher hasher = buildHasher();
        hasher.putString(resource.stringValue());
        //FIXME: The order of the statements is not defined -> might result in different hash!
        RepositoryResult<Statement> statements = conn.getStatements(resource, null, null, true);
        try {
          while (statements.hasNext()) {
            Statement statement = statements.next();
            hasher.putString(statement.getPredicate().stringValue());
            hasher.putString(statement.getObject().stringValue());
            //TODO: statement modification date?
          }
        } finally {
          statements.close();
        }
        return hasher.hash().toString();
    }
View Full Code Here

        return hasher.hash().toString();
    }

    private static Hasher buildHasher() {
        HashFunction function = Hashing.goodFastHash(16);
        Hasher hasher = function.newHasher();
        return hasher;
    }
View Full Code Here

TOP

Related Classes of com.google.common.hash.Hasher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.