@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } BloomDimFilter that = (BloomDimFilter) o; if (!dimension.equals(that.dimension)) { return false; } if (hash != null ? !hash.equals(that.hash) : that.hash != null) { return false; } return extractionFn != null ? extractionFn.equals(that.extractionFn) : that.extractionFn == null; }
@DELETE @Path("/v1/proxy") @Produces(APPLICATION_JSON) public void cancelQuery( @QueryParam("uri") String uri, @QueryParam("hmac") String hash, @Context HttpServletRequest servletRequest, @Suspended AsyncResponse asyncResponse) { if (!hmac.hashString(uri, UTF_8).equals(HashCode.fromString(hash))) { throw badRequest(FORBIDDEN, "Failed to validate HMAC of URI"); } Request.Builder request = prepareDelete().setUri(URI.create(uri)); performRequest(servletRequest, asyncResponse, request, response -> responseWithHeaders(noContent(), response)); }
@GET @Path("/v1/proxy") @Produces(APPLICATION_JSON) public void getNext( @QueryParam("uri") String uri, @QueryParam("hmac") String hash, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) { if (!hmac.hashString(uri, UTF_8).equals(HashCode.fromString(hash))) { throw badRequest(FORBIDDEN, "Failed to validate HMAC of URI"); } Request.Builder request = prepareGet().setUri(URI.create(uri)); performRequest(servletRequest, asyncResponse, request, response -> buildResponse(uriInfo, response)); }
public void testCombineOrdered_randomHashCodes() { Random random = new Random(7); List<HashCode> hashCodes = Lists.newArrayList(); for (int i = 0; i < 10; i++) { hashCodes.add(HashCode.fromLong(random.nextLong())); } HashCode hashCode1 = Hashing.combineOrdered(hashCodes); Collections.shuffle(hashCodes, random); HashCode hashCode2 = Hashing.combineOrdered(hashCodes); assertFalse(hashCode1.equals(hashCode2)); }
public static Model deserialize(Slice slice) { 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); requireNonNull(algorithm, format("Unsupported algorith %d", id)); int hyperparameterLength = slice.getInt(HYPERPARAMETER_LENGTH_OFFSET); byte[] hyperparameterBytes = slice.getBytes(HYPERPARAMETERS_OFFSET, hyperparameterLength); int dataLengthOffset = HYPERPARAMETERS_OFFSET + hyperparameterLength; long dataLength = slice.getLong(dataLengthOffset); int dataOffset = dataLengthOffset + SIZE_OF_LONG; byte[] data = slice.getBytes(dataOffset, (int) dataLength); try { Method deserialize = algorithm.getMethod("deserialize", byte[].class); return (Model) deserialize.invoke(null, new Object[] {data}); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new RuntimeException(e); } }
public void testCombineOrdered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); assertEquals(hash32, Hashing.combineOrdered(ImmutableList.of(hash32))); assertEquals( HashCode.fromBytes(new byte[] {(byte) 0x80, 0, 0, 0}), Hashing.combineOrdered(ImmutableList.of(hash32, hash32))); assertEquals( HashCode.fromBytes(new byte[] {(byte) 0xa0, 0, 0, 0}), Hashing.combineOrdered(ImmutableList.of(hash32, hash32, hash32))); assertFalse( Hashing.combineOrdered(ImmutableList.of(hash31, hash32)) .equals(Hashing.combineOrdered(ImmutableList.of(hash32, hash31)))); }
public void testObjectHashCodeWithSameLowOrderBytes() { // These will have the same first 4 bytes (all 0). byte[] bytesA = new byte[5]; byte[] bytesB = new byte[5]; // Change only the last (5th) byte bytesA[4] = (byte) 0xbe; bytesB[4] = (byte) 0xef; HashCode hashCodeA = HashCode.fromBytes(bytesA); HashCode hashCodeB = HashCode.fromBytes(bytesB); // They aren't equal... assertFalse(hashCodeA.equals(hashCodeB)); // But they still have the same Object#hashCode() value. // Technically not a violation of the equals/hashCode contract, but...? assertEquals(hashCodeA.hashCode(), hashCodeB.hashCode()); }
if (!hashCode.equals(o.hashCode)) { return false;
private List<Path> findModifiedFiles(Set<Path> filesOnDisk) { List<Path> modifiedFileList = new ArrayList<Path>(); for (Path file : filesOnDisk) { HashCode storedHashCode = hashCodeMap.get(file); HashCode newHashCode = hash(file); if (storedHashCode != null && !storedHashCode.equals(newHashCode) && newHashCode != null) { modifiedFileList.add(file); hashCodeMap.put(file, newHashCode); } } return modifiedFileList; }
private boolean contentHashChanged(Path monitoredFile) { HashCode newHashCode = fileContentMd5(monitoredFile); boolean changed = !hashCode.getAndSet(newHashCode).equals(newHashCode); LOGGER.debug("contentHashChanged probe. Changed={}", changed); return changed; }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { HashCode sentHash = HashCode.fromInt(msg.readInt()); HashCode hash = Hashing.murmur3_32().hashBytes(msg.array(), msg.readerIndex(), msg.readableBytes()); out.add(msg); if (sentHash.equals(hash)) { System.out.println("Hashes matches"); } else { System.out.println("Hashes no matches"); } } }
/** * To {@code Blob} instances are considered equal iff they have the * same SHA-256 hash code are equal. * @param other */ @Override public boolean equals(Object other) { if (other == this) { return true; } if (other instanceof AbstractBlob) { AbstractBlob that = (AbstractBlob) other; // optimize the comparison if both this and the other blob // already have pre-computed SHA-256 hash codes synchronized (this) { if (hashCode != null) { synchronized (that) { if (that.hashCode != null) { return hashCode.equals(that.hashCode); } } } } } return other instanceof Blob && equal(this, (Blob) other); }
public static void install(Project project) { File f = project.file(PUPPET_PATH); try (InputStream in = InstallPuppet.class.getResourceAsStream("/unityPuppet.dll")) { Log.L.info("Unity puppet installed {}", f.exists()); if (f.exists()) { HashCode currentHash = Files.hash(f, Hashing.md5()); HashCode newHash = new HashingInputStream(Hashing.md5(), in).hash(); boolean upToDate = currentHash.equals(newHash); Log.L.info("Unity puppet up to date {}", upToDate); if (upToDate) { return; } } Files.createParentDirs(f); try (FileOutputStream o = new FileOutputStream(f)) { ByteStreams.copy(in, o); } } catch (IOException e) { throw new UncheckedIOException(e); } }
@DELETE @Path("/v1/proxy") @Produces(APPLICATION_JSON) public void cancelQuery( @QueryParam("uri") String uri, @QueryParam("hmac") String hash, @Context HttpServletRequest servletRequest, @Suspended AsyncResponse asyncResponse) { if (!hmac.hashString(uri, UTF_8).equals(HashCode.fromString(hash))) { throw badRequest(FORBIDDEN, "Failed to validate HMAC of URI"); } Request.Builder request = prepareDelete().setUri(URI.create(uri)); performRequest(servletRequest, asyncResponse, request, response -> responseWithHeaders(noContent(), response)); }
@GET @Path("/v1/proxy") @Produces(APPLICATION_JSON) public void getNext( @QueryParam("uri") String uri, @QueryParam("hmac") String hash, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) { if (!hmac.hashString(uri, UTF_8).equals(HashCode.fromString(hash))) { throw badRequest(FORBIDDEN, "Failed to validate HMAC of URI"); } Request.Builder request = prepareGet().setUri(URI.create(uri)); performRequest(servletRequest, asyncResponse, request, response -> buildResponse(uriInfo, response)); }
public static Model deserialize(Slice slice) { 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); requireNonNull(algorithm, format("Unsupported algorith %d", id)); int hyperparameterLength = slice.getInt(HYPERPARAMETER_LENGTH_OFFSET); byte[] hyperparameterBytes = slice.getBytes(HYPERPARAMETERS_OFFSET, hyperparameterLength); int dataLengthOffset = HYPERPARAMETERS_OFFSET + hyperparameterLength; long dataLength = slice.getLong(dataLengthOffset); int dataOffset = dataLengthOffset + SIZE_OF_LONG; byte[] data = slice.getBytes(dataOffset, (int) dataLength); try { Method deserialize = algorithm.getMethod("deserialize", byte[].class); return (Model) deserialize.invoke(null, new Object[] {data}); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new RuntimeException(e); } }
public void testCombineOrdered_randomHashCodes() { Random random = new Random(7); List<HashCode> hashCodes = Lists.newArrayList(); for (int i = 0; i < 10; i++) { hashCodes.add(HashCode.fromLong(random.nextLong())); } HashCode hashCode1 = Hashing.combineOrdered(hashCodes); Collections.shuffle(hashCodes, random); HashCode hashCode2 = Hashing.combineOrdered(hashCodes); assertFalse(hashCode1.equals(hashCode2)); }
public void testCombineOrdered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); assertEquals(hash32, Hashing.combineOrdered(ImmutableList.of(hash32))); assertEquals(HashCode.fromBytes(new byte[] { (byte) 0x80, 0, 0, 0 }), Hashing.combineOrdered(ImmutableList.of(hash32, hash32))); assertEquals(HashCode.fromBytes(new byte[] { (byte) 0xa0, 0, 0, 0 }), Hashing.combineOrdered(ImmutableList.of(hash32, hash32, hash32))); assertFalse( Hashing.combineOrdered(ImmutableList.of(hash31, hash32)).equals( Hashing.combineOrdered(ImmutableList.of(hash32, hash31)))); }
public void testObjectHashCodeWithSameLowOrderBytes() { // These will have the same first 4 bytes (all 0). byte[] bytesA = new byte[5]; byte[] bytesB = new byte[5]; // Change only the last (5th) byte bytesA[4] = (byte) 0xbe; bytesB[4] = (byte) 0xef; HashCode hashCodeA = HashCode.fromBytes(bytesA); HashCode hashCodeB = HashCode.fromBytes(bytesB); // They aren't equal... assertFalse(hashCodeA.equals(hashCodeB)); // But they still have the same Object#hashCode() value. // Technically not a violation of the equals/hashCode contract, but...? assertEquals(hashCodeA.hashCode(), hashCodeB.hashCode()); }
@Test public void testWithField() { Employee rick = new Employee(); String actualJson = toJson(rick); puts(actualJson); /* Convert it back to an employee. */ Map<String, Object> fromJson = (Map<String, Object>) fromJson(actualJson); /* Grab the password an convert it into a HashCode. */ String password = idxStr(fromJson, "password"); fromJson = Maps.copy(fromJson); /* Convert and shove it back into the map. */ idx(fromJson, "password", HashCode.fromString(password)); /* Now convert the map into an Employee. */ Employee rick2 = fromMap(fromJson, Employee.class); ok = rick.firstName == rick2.firstName.intern() || die(); ok = rick.password.equals(rick2.password) || die(rick2.password); }