Package com.google.common.hash

Examples of com.google.common.hash.Hasher


    }

    @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


        long msb = frame.readLong();
        long lsb = frame.readLong();
        long hash = frame.readLong();
        byte[] segment = new byte[len - 25];
        frame.getBytes(29, segment);
        Hasher hasher = Hashing.murmur3_32().newHasher();
        long check = hasher.putBytes(segment).hash().padToLong();
        if (hash == check) {
            SegmentId id = new SegmentId(store.getTracker(), msb, lsb);
            Segment s = new Segment(store.getTracker(), id,
                    ByteBuffer.wrap(segment));
            log.debug("received type {} with id {} and size {}", type, id,
View Full Code Here

        SegmentId id = s.getSegmentId();
        ByteArrayOutputStream baos = new ByteArrayOutputStream(s.size());
        s.writeTo(baos);
        byte[] segment = baos.toByteArray();

        Hasher hasher = Hashing.murmur3_32().newHasher();
        long hash = hasher.putBytes(segment).hash().padToLong();

        int len = segment.length + EXTRA_HEADERS_WO_SIZE;
        out.writeInt(len);
        out.writeByte(Messages.HEADER_SEGMENT);
        out.writeLong(id.getMostSignificantBits());
View Full Code Here

   * Hashes the contents of this byte source using the given hash function.
   *
   * @throws IOException if an I/O error occurs in the process of reading from this source
   */
  public HashCode hash(HashFunction hashFunction) throws IOException {
    Hasher hasher = hashFunction.newHasher();
    copyTo(Funnels.asOutputStream(hasher));
    return hasher.hash();
  }
View Full Code Here

    private HashCode getPartitionHash(PartitionContext partitionContext) {
        // The precise implementation of this method isn't particularly important.  There are lots of ways we can hash
        // the data in the PartitionContext.  It just needs to be deterministic and to take into account the values in
        // the PartitionContext for the configured partition keys.
        Hasher hasher = Hashing.md5().newHasher();
        boolean empty = true;
        if (_partitionKeys.isEmpty()) {
            // Use the default context.
            Object value = partitionContext.get();
            if (value != null) {
                putUnencodedChars(hasher, value.toString());
                empty = false;
            }
        }
        for (String partitionKey : _partitionKeys) {
            Object value = partitionContext.get(partitionKey);
            if (value != null) {
                // Include both the key and value in the hash so "reviewId" of 1 and "reviewerId" of 1 hash differently.
                putUnencodedChars(hasher, partitionKey);
                putUnencodedChars(hasher, value.toString());
                empty = false;
            }
        }
        if (empty) {
            // When the partition context has no relevant values that means we should ignore the partition context and
            // don't filter the end points based on partition.  Return null to indicate this.
            return null;
        }
        return hasher.hash();
    }
View Full Code Here

        // randomly generated ranges to each end point.  The individual ranges may vary widely in size, but, with
        // sufficient # of entries per end point, the overall amount of data assigned to each server tends to even out
        // with minimal variation (256 entries per server yields roughly 5% variation in server load).
        List<Integer> list = Lists.newArrayListWithCapacity(_entriesPerEndPoint);
        for (int i = 0; list.size() < _entriesPerEndPoint; i++) {
            Hasher hasher = Hashing.md5().newHasher();
            hasher.putInt(i);
            putUnencodedChars(hasher, endPointId);
            ByteBuffer buf = ByteBuffer.wrap(hasher.hash().asBytes());
            while (buf.hasRemaining() && list.size() < _entriesPerEndPoint) {
                list.add(buf.getInt());
            }
        }
        return list;
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

   * Hashes the contents of this byte source using the given hash function.
   *
   * @throws IOException if an I/O error occurs in the process of reading from this source
   */
  public HashCode hash(HashFunction hashFunction) throws IOException {
    Hasher hasher = hashFunction.newHasher();
    copyTo(Funnels.asOutputStream(hasher));
    return hasher.hash();
  }
View Full Code Here

        final Integer port, final String user, final String password, final String managerIp,
        final Integer managerPort, final String managerUser, final String managerPassword,
        final String agentIp, final Integer agentPort, final String agentUser,
        final String agentPassword)
    {
        final Hasher hasher = Hashing.md5().newHasher();

        // End point
        hasher.putBytes(nullToEmpty(endPoint).getBytes());

        // Host attributes
        hasher.putBytes(nullToEmpty(ip).getBytes());
        hasher.putBytes(nullToEmpty(user).getBytes());
        hasher.putBytes(nullToEmpty(password).getBytes());
        hasher.putBytes(extractPort(port).getBytes());

        // Manager attributes
        hasher.putBytes(nullToEmpty(managerIp).getBytes());
        hasher.putBytes(nullToEmpty(managerUser).getBytes());
        hasher.putBytes(nullToEmpty(managerPassword).getBytes());
        hasher.putBytes(extractPort(managerPort).getBytes());

        // Agent attributes
        hasher.putBytes(nullToEmpty(agentIp).getBytes());
        hasher.putBytes(nullToEmpty(agentUser).getBytes());
        hasher.putBytes(nullToEmpty(agentPassword).getBytes());
        hasher.putBytes(extractPort(agentPort).getBytes());

        return hasher.hash().toString();
    }
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

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.