当前位置: 首页>>代码示例>>Java>>正文


Java Hasher.putString方法代码示例

本文整理汇总了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();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:SignatureUtils.java

示例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();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:28,代码来源:CheckRequestAggregator.java

示例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();
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:19,代码来源:QuotaRequestAggregator.java

示例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);
}
 
开发者ID:aws,项目名称:elastic-load-balancing-tools,代码行数:19,代码来源:NullHasherTest.java

示例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;
}
 
开发者ID:zhoujia123,项目名称:ElasticJob,代码行数:27,代码来源:RegistryCenterFactory.java

示例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;
}
 
开发者ID:ErinDavid,项目名称:elastic-config,代码行数:29,代码来源:RegistryCenterFactory.java

示例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();
}
 
开发者ID:spotify,项目名称:heroic,代码行数:23,代码来源:Series.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:ETagResponseFilter.java

示例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!");
}
 
开发者ID:y-lan,项目名称:presto,代码行数:23,代码来源:TestTimeZoneKey.java

示例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();
}
 
开发者ID:icode,项目名称:ameba,代码行数:17,代码来源:DatabaseMigrationResolver.java

示例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();
}
 
开发者ID:gigony,项目名称:GUITester-core,代码行数:19,代码来源:IDGenerator_JFC.java

示例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();
}
 
开发者ID:gigony,项目名称:GUITester-core,代码行数:21,代码来源:IDGenerator_JFC.java

示例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();
}
 
开发者ID:apache,项目名称:marmotta,代码行数:20,代码来源:ETagGenerator.java

示例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));
}
 
开发者ID:facebook,项目名称:buck,代码行数:24,代码来源:MacroExpander.java

示例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();
}
 
开发者ID:apache,项目名称:usergrid,代码行数:20,代码来源:ServiceInfo.java


注:本文中的com.google.common.hash.Hasher.putString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。