本文整理汇总了Java中com.google.common.hash.Hasher.putString方法的典型用法代码示例。如果您正苦于以下问题:Java Hasher.putString方法的具体用法?Java Hasher.putString怎么用?Java Hasher.putString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.hash.Hasher
的用法示例。
在下文中一共展示了Hasher.putString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: genSignature
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
public static String genSignature(HttpServletRequestEx requestEx) {
Hasher hasher = Hashing.sha256().newHasher();
hasher.putString(requestEx.getRequestURI(), StandardCharsets.UTF_8);
for (String paramName : paramNames) {
String paramValue = requestEx.getHeader(paramName);
if (paramValue != null) {
hasher.putString(paramName, StandardCharsets.UTF_8);
hasher.putString(paramValue, StandardCharsets.UTF_8);
System.out.printf("%s %s\n", paramName, paramValue);
}
}
byte[] bytes = requestEx.getBodyBytes();
if (bytes != null) {
hasher.putBytes(bytes, 0, requestEx.getBodyBytesLength());
}
return hasher.hash().toString();
}
示例2: sign
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* 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}
*/
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();
}
示例3: sign
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@VisibleForTesting
static HashCode sign(AllocateQuotaRequest req) {
Hasher h = Hashing.md5().newHasher();
QuotaOperation o = req.getAllocateOperation();
h.putString(o.getMethodName(), StandardCharsets.UTF_8);
h.putChar('\0');
h.putString(o.getConsumerId(), StandardCharsets.UTF_8);
ImmutableSortedSet.Builder<String> builder =
new ImmutableSortedSet.Builder<>(Ordering.natural());
for (MetricValueSet mvSet : o.getQuotaMetricsList()) {
builder.add(mvSet.getMetricName());
}
for (String metricName : builder.build()) {
h.putChar('\0');
h.putString(metricName, StandardCharsets.UTF_8);
}
return h.hash();
}
示例4: testBasics
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Test
public void testBasics() {
Hasher hasher = NullHasher.INSTANCE;
assertEquals(0, hasher.hash().asInt());
hasher.putBoolean(false);
hasher.putByte((byte) 3);
hasher.putBytes(new byte[0]);
hasher.putBytes(null, 3, 3);
hasher.putChar('c');
hasher.putDouble(3.3);
hasher.putFloat(3.4f);
hasher.putInt(7);
hasher.putLong(3);
hasher.putObject(null, null);
hasher.putShort((short) 7);
hasher.putString(null, null);
hasher.putUnencodedChars(null);
}
示例5: createCoordinatorRegistryCenter
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* 创建注册中心.
*
* @param connectString 注册中心连接字符串
* @param namespace 注册中心命名空间
* @param digest 注册中心凭证
* @return 注册中心对象
*/
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) {
Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8);
if (digest.isPresent()) {
hasher.putString(digest.get(), Charsets.UTF_8);
}
HashCode hashCode = hasher.hash();
if (registryCenterMap.containsKey(hashCode)) {
return registryCenterMap.get(hashCode);
}
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace);
if (digest.isPresent()) {
zkConfig.setDigest(digest.get());
}
CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig);
result.init();
registryCenterMap.putIfAbsent(hashCode, result);
return result;
}
示例6: createCoordinatorRegistryCenter
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* 创建注册中心.
*
* @param connectString 注册中心连接字符串
* @param namespace 注册中心命名空间
* @param digest 注册中心凭证
* @return 注册中心对象
*/
public static ElasticConfigRegistryCenter createCoordinatorRegistryCenter(final String connectString,
final String namespace, final Optional<String> digest) {
Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8)
.putString(namespace, Charsets.UTF_8);
if (digest.isPresent()) {
hasher.putString(digest.get(), Charsets.UTF_8);
}
HashCode hashCode = hasher.hash();
if (registryCenterMap.containsKey(hashCode)) {
return registryCenterMap.get(hashCode);
}
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace);
if (digest.isPresent()) {
zkConfig.setDigest(digest.get());
}
ElasticConfigRegistryCenter result = new ZookeeperRegistryCenter(zkConfig);
result.init();
registryCenterMap.putIfAbsent(hashCode, result);
return result;
}
示例7: generateHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
private HashCode generateHash() {
final Hasher hasher = HASH_FUNCTION.newHasher();
if (key != null) {
hasher.putString(key, Charsets.UTF_8);
}
for (final Map.Entry<String, String> kv : tags.entrySet()) {
final String k = kv.getKey();
final String v = kv.getValue();
if (k != null) {
hasher.putString(k, Charsets.UTF_8);
}
if (v != null) {
hasher.putString(v, Charsets.UTF_8);
}
}
return hasher.hash();
}
示例8: addHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Helper method to add entity to hash. If there is an invalid entity type it will return false
*
* @param entity the entity object to analyze and extract JSON for hashing it
* @param hasher the hasher used to add the hashes
*/
protected boolean addHash(Object entity, Hasher hasher) {
// get entity type
EntityType entityType = getElementType(entity);
// check
if (entityType == UNKNOWN) {
// unknown entity type, cannot perform hash
return false;
}
// add hash if all is OK
try {
hasher.putString(getJson(entity, entityType), Charset.defaultCharset());
} catch (RuntimeException e) {
return false;
}
return true;
}
示例9: testZoneKeyData
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Test
public void testZoneKeyData()
throws Exception
{
Hasher hasher = Hashing.murmur3_128().newHasher();
SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>()
{
@Override
public int compare(TimeZoneKey left, TimeZoneKey right)
{
return Short.compare(left.getKey(), right.getKey());
}
}, TimeZoneKey.getTimeZoneKeys());
for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) {
hasher.putShort(timeZoneKey.getKey());
hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8);
}
// Zone file should not (normally) be changed, so let's make is more difficult
assertEquals(hasher.hash().asLong(), 5498515770239515435L, "zone-index.properties file contents changed!");
}
示例10: calculateChecksum
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
static int calculateChecksum(String str) {
Hasher hasher = Hashing.murmur3_32().newHasher();
BufferedReader bufferedReader = new BufferedReader(new StringReader(str));
try {
String line;
while ((line = bufferedReader.readLine()) != null) {
hasher.putString(line.trim(), Charsets.UTF_8);
}
} catch (IOException e) {
String message = "Unable to calculate checksum";
throw new FlywayException(message, e);
}
return hasher.hash().asInt();
}
示例11: getComponentHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public HashCode getComponentHash(ComponentModel src, HashCode parentHashCode) {
Hasher hasher = hf.newHasher();
if (parentHashCode != null)
hasher.putBytes(parentHashCode.asBytes());
Map<String, String> srcProperties = src.getProperties();
hasher.putString(srcProperties.get("title"), Charsets.UTF_8);
for (String key : structuralPropertyList) {
String value = srcProperties.get(key);
if (value != null)
hasher.putString(value, Charsets.UTF_8);
else
hasher.putBoolean(false);
}
return hasher.hash();
}
示例12: getEventHash
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
@Override
public HashCode getEventHash(EventModel src) {
Hasher hasher = hf.newHasher();
String id = src.getComponentModel().get("id");
if (id != null)
hasher.putString(id, Charsets.UTF_8);
else
hasher.putBoolean(false);
hasher.putInt(src.getValueHash());
String componentIdx = src.getComponentModel().get("componentIndex");
if (componentIdx != null)
hasher.putString(componentIdx, Charsets.UTF_8);
else
hasher.putBoolean(false);
return hasher.hash();
}
示例13: getWeakETag
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
public static String getWeakETag(RepositoryConnection conn, Resource resource) throws RepositoryException {
if (resource == null) return "";
Hasher hasher = buildHasher();
hasher.putString(resource.stringValue(), Charset.defaultCharset());
//FIXME: The order of the statements is not defined -> might result in different hash!
RepositoryResult<Statement> statements = conn.getStatements(resource, null, null, true);
try {
while (statements.hasNext()) {
Statement statement = statements.next();
hasher.putString(statement.getPredicate().stringValue(), Charset.defaultCharset());
hasher.putString(statement.getObject().stringValue(), Charset.defaultCharset());
//TODO: statement modification date?
}
} finally {
statements.close();
}
return hasher.hash().toString();
}
示例14: expandForFile
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
/**
* Expand the input given for the this macro to some string, which is intended to be written to a
* file.
*/
default Arg expandForFile(
BuildTarget target,
CellPathResolver cellNames,
BuildRuleResolver resolver,
ImmutableList<String> input,
Object precomputedWork)
throws MacroException {
// "prefix" should give a stable name, so that the same delegate with the same input can output
// the same file. We won't optimise for this case, since it's actually unlikely to happen within
// a single run, but using a random name would cause 'buck-out' to expand in an uncontrolled
// manner.
Hasher hasher = Hashing.sha1().newHasher();
hasher.putString(getClass().getName(), UTF_8);
input.forEach(s -> hasher.putString(s, UTF_8));
return makeExpandToFileArg(
target,
hasher.hash().toString(),
expand(target, cellNames, resolver, input, precomputedWork));
}
示例15: ServiceInfo
import com.google.common.hash.Hasher; //导入方法依赖的package包/类
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, UTF_8 );
}
hashCode = hasher.hash().asInt();
}