Examples of Hasher


Examples of com.google.common.hash.Hasher

    if (buf.length() == 0) {
      return null;
    }

    LOG.debug("Creating jar file for coprocessor classes: " + buf.toString());
    final Hasher hasher = Hashing.md5().newHasher();
    final byte[] buffer = new byte[COPY_BUFFER_SIZE];

    final Map<String, URL> dependentClasses = new HashMap<String, URL>();
    for (Class<? extends Coprocessor> clz : classes) {
      Dependencies.findClassDependencies(clz.getClassLoader(), new Dependencies.ClassAcceptor() {
        @Override
        public boolean accept(String className, final URL classUrl, URL classPathUrl) {
          // Assuming the endpoint and protocol class doesn't have dependencies
          // other than those comes with HBase and Java.
          if (className.startsWith("co.cask")) {
            if (!dependentClasses.containsKey(className)) {
              dependentClasses.put(className, classUrl);
            }
            return true;
          }
          return false;
        }
      }, clz.getName());
    }

    if (!dependentClasses.isEmpty()) {
      LOG.debug("Adding " + dependentClasses.size() + " classes to jar");
      File jarFile = File.createTempFile(filePrefix, ".jar");
      try {
        JarOutputStream jarOutput = null;
        try {
          jarOutput = new JarOutputStream(new FileOutputStream(jarFile));
          for (Map.Entry<String, URL> entry : dependentClasses.entrySet()) {
            try {
              jarOutput.putNextEntry(new JarEntry(entry.getKey().replace('.', File.separatorChar) + ".class"));
              InputStream inputStream = entry.getValue().openStream();

              try {
                int len = inputStream.read(buffer);
                while (len >= 0) {
                  hasher.putBytes(buffer, 0, len);
                  jarOutput.write(buffer, 0, len);
                  len = inputStream.read(buffer);
                }
              } finally {
                inputStream.close();
              }
            } catch (IOException e) {
              LOG.info("Error writing to jar", e);
              throw Throwables.propagate(e);
            }
          }
        } finally {
          if (jarOutput != null) {
            jarOutput.close();
          }
        }

        // Copy jar file into HDFS
        // Target path is the jarDir + jarMD5.jar
        final Location targetPath = jarDir.append("coprocessor" + hasher.hash().toString() + ".jar");

        // If the file exists and having same since, assume the file doesn't changed
        if (targetPath.exists() && targetPath.length() == jarFile.length()) {
          return targetPath;
        }
View Full Code Here

Examples of com.google.common.hash.Hasher

    }

    @Override
    public int hashCode() {
        HashFunction hf = Hashing.goodFastHash(32);
        Hasher h = hf.newHasher();
        h.putInt(slots.size());
        for (int i=0; i<slots.size(); i++) {
            h.putInt(slots.get(i).size());
            for (int j=0; j<slots.size(); j++) {
                h.putBytes(slots.get(i).get(j).getLowerRange());
                h.putBytes(slots.get(i).get(j).getUpperRange());
            }
        }
        return h.hash().asInt();
    }
View Full Code Here

Examples of com.google.common.hash.Hasher

  //

  /** {@inheritDoc} */
  @Override
  public synchronized String getFingerprint() {
    Hasher hash = Hashing.sha256().newHasher();
    hash.putString(profile.getFingerprint());

    hash.putString("Posts(");
    for (Post post : getPosts()) {
      hash.putString("Post(").putString(post.getId()).putString(")");
    }
    hash.putString(")");

    List<PostReply> replies = new ArrayList<PostReply>(getReplies());
    Collections.sort(replies, Reply.TIME_COMPARATOR);
    hash.putString("Replies(");
    for (PostReply reply : replies) {
      hash.putString("Reply(").putString(reply.getId()).putString(")");
    }
    hash.putString(")");

    List<String> likedPostIds = new ArrayList<String>(getLikedPostIds());
    Collections.sort(likedPostIds);
    hash.putString("LikedPosts(");
    for (String likedPostId : likedPostIds) {
      hash.putString("Post(").putString(likedPostId).putString(")");
    }
    hash.putString(")");

    List<String> likedReplyIds = new ArrayList<String>(getLikedReplyIds());
    Collections.sort(likedReplyIds);
    hash.putString("LikedReplies(");
    for (String likedReplyId : likedReplyIds) {
      hash.putString("Reply(").putString(likedReplyId).putString(")");
    }
    hash.putString(")");

    hash.putString("Albums(");
    for (Album album : rootAlbum.getAlbums()) {
      if (!Album.NOT_EMPTY.apply(album)) {
        continue;
      }
      hash.putString(album.getFingerprint());
    }
    hash.putString(")");

    return hash.hash().toString();
  }
View Full Code Here

Examples of com.google.common.hash.Hasher

  // FINGERPRINTABLE METHODS
  //

  @Override
  public String getFingerprint() {
    Hasher hash = Hashing.sha256().newHasher();
    hash.putString("Image(");
    hash.putString("ID(").putString(id).putString(")");
    hash.putString("Title(").putString(title).putString(")");
    hash.putString("Description(").putString(description).putString(")");
    hash.putString(")");
    return hash.hash().toString();
  }
View Full Code Here

Examples of com.google.common.hash.Hasher

  /**
   * {@inheritDoc}
   */
  @Override
  public String getFingerprint() {
    Hasher hash = Hashing.sha256().newHasher();
    hash.putString("Profile(");
    if (firstName != null) {
      hash.putString("FirstName(").putString(firstName).putString(")");
    }
    if (middleName != null) {
      hash.putString("MiddleName(").putString(middleName).putString(")");
    }
    if (lastName != null) {
      hash.putString("LastName(").putString(lastName).putString(")");
    }
    if (birthDay != null) {
      hash.putString("BirthDay(").putInt(birthDay).putString(")");
    }
    if (birthMonth != null) {
      hash.putString("BirthMonth(").putInt(birthMonth).putString(")");
    }
    if (birthYear != null) {
      hash.putString("BirthYear(").putInt(birthYear).putString(")");
    }
    if (avatar != null) {
      hash.putString("Avatar(").putString(avatar).putString(")");
    }
    hash.putString("ContactInformation(");
    for (Field field : fields) {
      hash.putString(field.getName()).putString("(").putString(field.getValue()).putString(")");
    }
    hash.putString(")");
    hash.putString(")");

    return hash.hash().toString();
  }
View Full Code Here

Examples of com.google.common.hash.Hasher

  // FINGERPRINTABLE METHODS
  //

  @Override
  public String getFingerprint() {
    Hasher hash = Hashing.sha256().newHasher();
    hash.putString("Album(");
    hash.putString("ID(").putString(id).putString(")");
    hash.putString("Title(").putString(title).putString(")");
    hash.putString("Description(").putString(description).putString(")");
    if (albumImage != null) {
      hash.putString("AlbumImage(").putString(albumImage).putString(")");
    }

    /* add nested albums. */
    hash.putString("Albums(");
    for (Album album : albums) {
      hash.putString(album.getFingerprint());
    }
    hash.putString(")");

    /* add images. */
    hash.putString("Images(");
    for (Image image : getImages()) {
      if (image.isInserted()) {
        hash.putString(image.getFingerprint());
      }
    }
    hash.putString(")");

    hash.putString(")");
    return hash.hash().toString();
  }
View Full Code Here

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());
        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

Examples of com.google.common.hash.Hasher

     * @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

Examples of com.google.common.hash.Hasher

    }
   
    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

Examples of com.google.common.hash.Hasher

//    }
   
    public static String getWeakETag(RepositoryConnection conn, Resource 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
TOP
Copyright © 2018 www.massapi.com. 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.