List of usage examples for com.google.common.hash Hashing md5
public static HashFunction md5()
From source file:jp.classmethod.aws.gradle.s3.AmazonS3FileUploadTask.java
private String md5() throws IOException { return Files.hash(getFile(), Hashing.md5()).toString(); }
From source file:com.philbeaudoin.quebec.server.session.ServerSessionManagerImpl.java
@Inject public ServerSessionManagerImpl(ObjectifyServiceWrapper objectifyServiceWrapper, SecureRandomSingleton random, HttpServletRequest request, HttpServletResponse response) { this.objectifyServiceWrapper = objectifyServiceWrapper; this.random = random; this.request = request; this.response = response; hashFunction = Hashing.md5(); }
From source file:com.netflix.dynomitemanager.sidecore.utils.SystemUtils.java
/** * Get a Md5 string which is similar to OS Md5sum *//*from ww w .j a v a2s . c om*/ public static String md5(File file) { if (file == null) throw new IllegalArgumentException("file cannot be null"); try { HashCode hc = Files.hash(file, Hashing.md5()); return toHex(hc.asBytes()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.aurora.scheduler.storage.log.LogPersistenceModule.java
@Override protected void configure() { bind(new TypeLiteral<Amount<Integer, Data>>() { }).annotatedWith(MaxEntrySize.class).toInstance(options.maxLogEntrySize); bind(LogManager.class).in(Singleton.class); bind(LogPersistence.class).in(Singleton.class); bind(Persistence.class).to(LogPersistence.class); expose(Persistence.class); expose(LogPersistence.class); bind(EntrySerializer.class).to(EntrySerializerImpl.class); // TODO(ksweeney): We don't need a cryptographic checksum here - assess performance of MD5 // versus a faster error-detection checksum like CRC32 for large Snapshots. @SuppressWarnings("deprecation") HashFunction hashFunction = Hashing.md5(); bind(HashFunction.class).annotatedWith(LogEntryHashFunction.class).toInstance(hashFunction); bind(SnapshotDeduplicator.class).to(SnapshotDeduplicatorImpl.class); install(new FactoryModuleBuilder().implement(StreamManager.class, StreamManagerImpl.class) .build(StreamManagerFactory.class)); }
From source file:org.eclipse.che.everrest.ETagResponseFilter.java
/** * Filter the given container response/*from w w w. j av a 2 s . c o m*/ * * @param containerResponse * the response to use */ public void doFilter(GenericContainerResponse containerResponse) { // get entity of the response Object entity = containerResponse.getEntity(); // no entity, skip if (entity == null) { return; } // Only handle JSON content if (!MediaType.APPLICATION_JSON_TYPE.equals(containerResponse.getContentType())) { return; } // Get the request ApplicationContext applicationContext = ApplicationContext.getCurrent(); Request request = applicationContext.getRequest(); // manage only GET requests if (!HttpMethod.GET.equals(request.getMethod())) { return; } // calculate hash with MD5 HashFunction hashFunction = Hashing.md5(); Hasher hasher = hashFunction.newHasher(); boolean hashingSuccess = true; // Manage a list if (entity instanceof List) { List<?> entities = (List) entity; for (Object simpleEntity : entities) { hashingSuccess = addHash(simpleEntity, hasher); if (!hashingSuccess) { break; } } } else { hashingSuccess = addHash(entity, hasher); } // if we're able to handle the hash if (hashingSuccess) { // get result of the hash HashCode hashCode = hasher.hash(); // Create the entity tag EntityTag entityTag = new EntityTag(hashCode.toString()); // Check the etag Response.ResponseBuilder builder = request.evaluatePreconditions(entityTag); // not modified ? if (builder != null) { containerResponse.setResponse(builder.tag(entityTag).build()); } else { // it has been changed, so send response with new ETag and entity Response.ResponseBuilder responseBuilder = Response.fromResponse(containerResponse.getResponse()) .tag(entityTag); containerResponse.setResponse(responseBuilder.build()); } } }
From source file:net.portalblockz.portalbot.webinterface.WebIntHandler.java
@Override public void handle(HttpExchange httpExchange) throws IOException { //TODO: Make this dynamic with a page, add support for multiple pages, make it actually display info! /*String header = "<h1 style=\"color:red\">portalBot IRC Bot</h1>"; String text =/*from ww w . j a v a 2s .co m*/ "<p>Welcome this is the beginning of a web interface for portalBot, its a WIP and right now does not have anything but this message on it!</p>";*/ String footer = "<br><center>© portalBlock " + year + "</center>"; if (customFile) { if (!indexHash.equals(Files.hash(indexFile, Hashing.md5()).toString())) { reply = readFile(indexFile); } } else { reply = defaultContent; } String newReply; newReply = reply.replaceAll("%servers%", getJSONServers()); newReply = newReply.replaceAll("%warns%", SmartListener.getJSONInfo()); //reply = reply.replaceAll("%stats%", getJSONSystemStats()); sendReply(httpExchange, newReply + footer); }
From source file:org.usergrid.services.ServiceInfo.java
public ServiceInfo(String name, boolean rootService, String rootType, String containerType, String collectionName, String itemType, List<String> patterns, List<String> collections) { this.name = name; this.rootService = rootService; this.rootType = rootType; this.containerType = containerType; this.collectionName = collectionName; this.itemType = itemType; this.patterns = patterns; this.collections = collections; Hasher hasher = Hashing.md5().newHasher(); for (String pattern : patterns) { hasher.putString(pattern);/*from w w w . j a va 2 s .co m*/ } hashCode = hasher.hash().asInt(); }
From source file:com.facebook.buck.zip.OverwritingZipOutputStream.java
@Override protected void actuallyPutNextEntry(ZipEntry entry) throws IOException { // We calculate the actual offset when closing the stream, so 0 is fine. currentEntry = new EntryAccounting(clock, entry, /* currentOffset */ 0); long md5 = Hashing.md5().hashUnencodedChars(entry.getName()).asLong(); String name = String.valueOf(md5); File file = new File(scratchDir, name); entries.put(file, currentEntry);/* w w w . j a va2 s .c o m*/ if (file.exists() && !file.delete()) { throw new ZipException("Unable to delete existing file: " + entry.getName()); } currentOutput = new BufferedOutputStream(new FileOutputStream(file)); }
From source file:net.malisis.advert.advert.Advert.java
protected String calculateHash(byte[] img) { return Hashing.md5().hashBytes(img).toString(); }
From source file:com.facebook.buck.codegen.SourceSigner.java
/** * Given the contents of a source file containing 0 or more existing signatures * or signature placeholders, calculates an updated signature and updates * the signatures in the source file./*from www. j a v a2 s .c o m*/ * * If the source file contains at least one signature, returns an Optional * containing the updated source file. Otherwise, returns Optional.absent(). */ public static final Optional<String> sign(String source) { Matcher matcher = SIGNATURE_OR_PLACEHOLDER_PATTERN.matcher(source); Hasher md5Hasher = Hashing.md5().newHasher(); int pos = 0; while (matcher.find()) { if (matcher.groupCount() == 1) { // Update the digest up to the matched md5, but then hash the // placeholder token instead of the md5. md5Hasher.putString(source.substring(pos, matcher.start()), Charsets.UTF_8); md5Hasher.putString(PLACEHOLDER, Charsets.UTF_8); } else { md5Hasher.putString(source.substring(pos, matcher.end()), Charsets.UTF_8); } pos = matcher.end(); } if (pos > 0) { md5Hasher.putString(source.substring(pos), Charsets.UTF_8); matcher.reset(); String newSignature = formatSignature(md5Hasher.hash().toString()); return Optional.of(matcher.replaceAll(newSignature)); } else { return Optional.absent(); } }