List of usage examples for com.google.common.hash Hasher putString
@Override Hasher putString(CharSequence charSequence, Charset charset);
From source file:com.google.api.control.aggregator.CheckRequestAggregator.java
/** * Obtains the {@code HashCode} for the contents of {@code value}. * * @param value a {@code CheckRequest} to be signed * @return the {@code HashCode} corresponding to {@code value} *//*ww w. j ava2 s . c o m*/ public static HashCode sign(CheckRequest value) { Hasher h = Hashing.md5().newHasher(); Operation o = value.getOperation(); if (o == null || Strings.isNullOrEmpty(o.getConsumerId()) || Strings.isNullOrEmpty(o.getOperationName())) { throw new IllegalArgumentException("CheckRequest should have a valid operation"); } h.putString(o.getConsumerId(), StandardCharsets.UTF_8); h.putChar('\0'); h.putString(o.getOperationName(), StandardCharsets.UTF_8); h.putChar('\0'); Signing.putLabels(h, o.getLabels()); for (MetricValueSet mvSet : o.getMetricValueSetsList()) { h.putString(mvSet.getMetricName(), StandardCharsets.UTF_8); h.putChar('\0'); for (MetricValue metricValue : mvSet.getMetricValuesList()) { MetricValues.putMetricValue(h, metricValue); } } return h.hash(); }
From source file:fr.ens.biologie.genomique.eoulsan.modules.mapping.hadoop.ReadsMapperHadoopModule.java
/** * Compute the checksum of a ZIP file./*from w w w. j a v a 2 s .c om*/ * @param in input stream * @return the checksum as a string * @throws IOException if an error occurs while creating the checksum */ private static String computeZipCheckSum(final InputStream in) throws IOException { ZipArchiveInputStream zais = new ZipArchiveInputStream(in); // Create Hash function final Hasher hs = Hashing.md5().newHasher(); // Store entries in a map final Map<String, long[]> map = new HashMap<>(); ZipArchiveEntry e; while ((e = zais.getNextZipEntry()) != null) { map.put(e.getName(), new long[] { e.getSize(), e.getCrc() }); } zais.close(); // Add values to hash function in an ordered manner for (String filename : new TreeSet<>(map.keySet())) { hs.putString(filename, StandardCharsets.UTF_8); for (long l : map.get(filename)) { hs.putLong(l); } } return hs.hash().toString(); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.model.Reports.java
public static String traceIdentityHash(ErrorReport report) { final Hasher hasher = Hashing.murmur3_128().newHasher(); visit(report, new ModelSwitch<Hasher>() { @Override//from w w w . j a v a 2 s .c o m public Hasher caseStackTraceElement(StackTraceElement element) { hasher.putString(element.getClassName(), UTF_8); hasher.putString(element.getMethodName(), UTF_8); hasher.putInt(element.getLineNumber()); return null; } }); String hash = hasher.hash().toString(); return hash; }
From source file:org.eclipse.epp.internal.logging.aeri.ui.model.Reports.java
public static String exactIdentityHash(ErrorReport report) { final Hasher hasher = Hashing.murmur3_128().newHasher(); ModelSwitch<Hasher> s = new ModelSwitch<Hasher>() { @Override/*from w w w . j av a2 s . com*/ public Hasher caseErrorReport(ErrorReport object) { hasher.putString(stripToEmpty(object.getEclipseProduct()), UTF_8); hasher.putString(stripToEmpty(object.getEclipseBuildId()), UTF_8); hasher.putString(stripToEmpty(object.getJavaRuntimeVersion()), UTF_8); hasher.putString(stripToEmpty(object.getOsgiOs()), UTF_8); hasher.putString(stripToEmpty(object.getOsgiOsVersion()), UTF_8); hasher.putString(stripToEmpty(object.getOsgiArch()), UTF_8); hasher.putString(stripToEmpty(object.getOsgiWs()), UTF_8); return null; }; @Override public Hasher caseStatus(Status object) { hasher.putString(stripToEmpty(object.getPluginId()), UTF_8); hasher.putString(stripToEmpty(object.getPluginVersion()), UTF_8); hasher.putString(stripToEmpty(object.getMessage()), UTF_8); hasher.putInt(object.getSeverity()); hasher.putInt(object.getCode()); return null; } @Override public Hasher caseBundle(org.eclipse.epp.internal.logging.aeri.ui.model.Bundle object) { hasher.putString(stripToEmpty(object.getName()), UTF_8); hasher.putString(stripToEmpty(object.getVersion()), UTF_8); return null; } @Override public Hasher caseStackTraceElement(StackTraceElement object) { hasher.putString(stripToEmpty(object.getClassName()), UTF_8); hasher.putString(stripToEmpty(object.getMethodName()), UTF_8); hasher.putInt(object.getLineNumber()); return null; } @Override public Hasher caseThrowable(Throwable object) { hasher.putString(stripToEmpty(object.getClassName()), UTF_8); hasher.putString(stripToEmpty(object.getMessage()), UTF_8); return null; } }; visit(report, s); String hash = hasher.hash().toString(); return hash; }
From source file:com.android.sdklib.devices.DeviceManager.java
/** * Returns the hardware properties defined in * {@link AvdManager#HARDWARE_INI} as a {@link Map}. * * This is intended to be dumped in the config.ini and already contains * the device name, manufacturer and device hash. * * @param d The {@link Device} from which to derive the hardware properties. * @return A {@link Map} of hardware properties. */// ww w . j ava 2 s . c om @NonNull public static Map<String, String> getHardwareProperties(@NonNull Device d) { Map<String, String> props = getHardwareProperties(d.getDefaultState()); for (State s : d.getAllStates()) { if (s.getKeyState().equals(KeyboardState.HIDDEN)) { props.put("hw.keyboard.lid", getBooleanVal(true)); } } HashFunction md5 = Hashing.md5(); Hasher hasher = md5.newHasher(); ArrayList<String> keys = new ArrayList<String>(props.keySet()); Collections.sort(keys); for (String key : keys) { if (key != null) { hasher.putString(key, Charsets.UTF_8); String value = props.get(key); hasher.putString(value == null ? "null" : value, Charsets.UTF_8); } } // store the hash method for potential future compatibility String hash = "MD5:" + hasher.hash().toString(); props.put(AvdManager.AVD_INI_DEVICE_HASH_V2, hash); props.remove(AvdManager.AVD_INI_DEVICE_HASH_V1); props.put(AvdManager.AVD_INI_DEVICE_NAME, d.getId()); props.put(AvdManager.AVD_INI_DEVICE_MANUFACTURER, d.getManufacturer()); return props; }
From source file:org.gradle.api.internal.hash.DefaultFileHasher.java
@Override public HashCode hash(TextResource resource) { Hasher hasher = createFileHasher(); hasher.putString(resource.getText(), Charsets.UTF_8); return hasher.hash(); }
From source file:org.gradle.groovy.scripts.internal.DefaultScriptSourceHasher.java
@Override public HashCode hash(ScriptSource scriptSource) { TextResource resource = scriptSource.getResource(); File file = resource.getFile(); if (file != null) { return fileHasher.hash(file); }//from w w w .ja v a 2s.c o m Hasher hasher = contentHasherFactory.create(); hasher.putString(resource.getText(), Charsets.UTF_8); return hasher.hash(); }
From source file:teetime.stage.MD5Stage.java
@Override protected void execute(final String element) { Hasher hasher = Hashing.md5().newHasher(); hasher.putString(element, charset); outputPort.send(hasher.hash().toString()); }
From source file:documents.Document.java
public int hashCode() { Hasher hf = Hashing.md5().newHasher(); metadata.forEach((k, v) -> hf.putString(v, Charset.defaultCharset())); return hf.hash().asInt(); }
From source file:org.fim.model.FileTime.java
@Override public void hashObject(Hasher hasher) { hasher.putString("FileTime", Charsets.UTF_8).putChar(HASH_FIELD_SEPARATOR).putLong(creationTime) .putChar(HASH_FIELD_SEPARATOR).putLong(lastModified); }