Package com.google.common.hash

Examples of com.google.common.hash.Hasher


        // Blobs are immutable so we can safely cache the hash
        if (!hashCode.isPresent()) {
            InputStream is = getNewStream();
            try {
                try {
                    Hasher hasher = Hashing.sha256().newHasher();
                    byte[] buf = new byte[0x1000];
                    int r;
                    while((r = is.read(buf)) != -1) {
                        hasher.putBytes(buf, 0, r);
                    }
                    hashCode = Optional.of(hasher.hash());
                }
                catch (IOException e) {
                    log.warn("Error while hashing stream", e);
                }
            }
View Full Code Here



    public IntArray(int[] data) {
        this.data = data;

        Hasher hasher = hashFunction.newHasher();
        for(int i : data) {
            hasher.putInt(i);
        }
        goodHashCode = hasher.hash();
    }
View Full Code Here

      return null;
    }
    FrameHeader header = frame.getHeader();
    byte[][] chunks = new byte[header.getChunkCount()][];

    Hasher hasher = hashFunction.newHasher();
    for (int i = 0; i < header.getChunkCount(); i++) {
      if (!entries.hasNext()) {
        logBadFrame(header, i);
        return null;
      }
      LogEntry logEntry = decodeLogEntry(entries.next());
      if (!isFrame(logEntry)) {
        logBadFrame(header, i);
        return logEntry;
      }
      Frame chunkFrame = logEntry.getFrame();
      if (!isChunk(chunkFrame)) {
        logBadFrame(header, i);
        return logEntry;
      }
      byte[] chunkData = chunkFrame.getChunk().getData();
      hasher.putBytes(chunkData);
      chunks[i] = chunkData;
    }
    if (!Arrays.equals(header.getChecksum(), hasher.hash().asBytes())) {
      throw new CodingException("Read back a framed log entry that failed its checksum");
    }
    return Entries.thriftBinaryDecode(Bytes.concat(chunks));
  }
View Full Code Here

  }

  public static HashCode hash(InputSupplier paramInputSupplier, HashFunction paramHashFunction)
    throws IOException
  {
    Hasher localHasher = paramHashFunction.newHasher();
    return (HashCode)readBytes(paramInputSupplier, new ByteProcessor()
    {
      public boolean processBytes(byte[] paramAnonymousArrayOfByte, int paramAnonymousInt1, int paramAnonymousInt2)
      {
        this.val$hasher.putBytes(paramAnonymousArrayOfByte, paramAnonymousInt1, paramAnonymousInt2);
View Full Code Here

            writer.print(labelsJsAfter);
        }
    }

    protected static void handleETagFor(RestxRequest req, RestxResponse resp, Iterable<Entry<String, String>> entries) {
        Hasher hasher = Hashing.sha1().newHasher();
        for (Entry<String, String> entry : entries) {
            hasher.putString(entry.getKey(), Charsets.UTF_8).putString(entry.getValue(), Charsets.UTF_8);
        }
        new ETag(hasher.hash().toString(), CacheControl.MUST_REVALIDATE).handleIn(req, resp);
    }
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.