Package com.google.common.hash

Examples of com.google.common.hash.HashCode


     * @param strToHash
     * @return the {@code ObjectId} generated from the string
     */
    public static ObjectId forString(final String strToHash) {
        Preconditions.checkNotNull(strToHash);
        HashCode hashCode = HASH_FUNCTION.hashString(strToHash, Charset.forName("UTF-8"));
        return new ObjectId(hashCode.asBytes(), false);
    }
View Full Code Here


    {
        int version = slice.getInt(VERSION_OFFSET);
        checkArgument(version == CURRENT_FORMAT_VERSION, format("Unsupported version: %d", version));

        byte[] modelHashBytes = slice.getBytes(HASH_OFFSET, 32);
        HashCode expectedHash = HashCode.fromBytes(modelHashBytes);
        HashCode actualHash = Hashing.sha256().hashBytes(slice.getBytes(ALGORITHM_OFFSET, slice.length() - ALGORITHM_OFFSET));
        checkArgument(actualHash.equals(expectedHash), "model hash does not match data");

        int id = slice.getInt(ALGORITHM_OFFSET);
        Class<? extends Model> algorithm = MODEL_SERIALIZATION_IDS.inverse().get(id);
        checkNotNull(algorithm, "Unsupported algorith %d", id);
View Full Code Here

        _entriesPerEndPoint = entriesPerEndPoint;
    }

    @Override
    public Iterable<ServiceEndPoint> filter(Iterable<ServiceEndPoint> endPoints, PartitionContext partitionContext) {
        HashCode partitionHash = getPartitionHash(partitionContext);
        if (partitionHash == null) {
            return endPoints;  // No partition hash means any server can handle the request.
        }

        // The choose() method is synchronized.  Do any prep work we can up front before calling into it.
View Full Code Here

   /** @deprecated use {@link #getContentMD5AsHashCode()} instead. */
   @Deprecated
   @Override
   public byte[] getContentMD5() {
      HashCode hashCode = getContentMD5AsHashCode();
      return hashCode == null ? null : hashCode.asBytes();
   }
View Full Code Here

   /** @deprecated use {@link #getContentMD5AsHashCode()} instead. */
   @Deprecated
   @Override
   public byte[] getContentMD5() {
      HashCode hashCode = getContentMD5AsHashCode();
      return hashCode == null ? null : hashCode.asBytes();
   }
View Full Code Here

     */
    public static String md5(File file)
    {
        try
        {
            HashCode hc = Files.hash(file, Hashing.md5());
            return toHex(hc.asBytes());
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
View Full Code Here

     * @return the hash or null if an error happened
     */
    @Nullable
    private static String getFileHash(@NonNull File file) {
        try {
            HashCode hashCode = Files.hash(file, Hashing.sha1());
            return hashCode.toString();
        } catch (IOException ignored) {

        }

        return null;
View Full Code Here

                        headerName.substring(USER_METADATA_PREFIX.length()),
                        Strings.nullToEmpty(request.getHeader(headerName)));
            }
        }

        HashCode contentMD5 = null;
        if (hasContentMD5) {
            boolean validDigest = true;
            String contentMD5String = request.getHeader(
                    HttpHeaders.CONTENT_MD5);
            if (contentMD5String == null) {
View Full Code Here

        response.addHeader(HttpHeaders.CONTENT_LANGUAGE,
                contentMetadata.getContentLanguage());
        response.addHeader(HttpHeaders.CONTENT_LENGTH,
                contentMetadata.getContentLength().toString());
        response.setContentType(contentMetadata.getContentType());
        HashCode contentMd5 = contentMetadata.getContentMD5AsHashCode();
        if (contentMd5 != null) {
            byte[] contentMd5Bytes = contentMd5.asBytes();
            response.addHeader(HttpHeaders.CONTENT_MD5,
                    BaseEncoding.base64().encode(contentMd5Bytes));
            response.addHeader(HttpHeaders.ETAG, "\"" +
                    BaseEncoding.base16().lowerCase().encode(contentMd5Bytes) +
                    "\"");
View Full Code Here

   *
   * @param id The byte array that may have been previously seen.
   * @return Whether the byte array is contained in the ByteArrayFilter.
   */
  public boolean containsAndAdd(byte[] id) {
    HashCode code = HASH_FUNC.hashBytes(id);
    int index = Math.abs(code.asInt()) & sizeMask;
    byte[] oldId = array.getAndSet(index, id);
    return Arrays.equals(id, oldId);
  }
View Full Code Here

TOP

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

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.