List of usage examples for com.google.common.hash Hashing sha1
public static HashFunction sha1()
From source file:org.sonatype.nexus.ssl.CertificateUtil.java
/** * Calculates the SHA1 of a Certificate. *//* w w w. j a v a2 s . co m*/ public static String calculateSha1(final Certificate certificate) throws CertificateEncodingException { checkNotNull(certificate); return Hashing.sha1().hashBytes(certificate.getEncoded()).toString().toUpperCase(Locale.US); }
From source file:com.facebook.buck.parser.DefaultParserTargetNodeFactory.java
@Override public TargetNode<?, ?> createTargetNode(Cell cell, Path buildFile, BuildTarget target, Map<String, Object> rawNode, Function<PerfEventId, SimplePerfEvent.Scope> perfEventScope) { BuildRuleType buildRuleType = parseBuildRuleTypeFromRawRule(cell, rawNode); // Because of the way that the parser works, we know this can never return null. Description<?> description = cell.getDescription(buildRuleType); UnflavoredBuildTarget unflavoredBuildTarget = target.withoutCell().getUnflavoredBuildTarget(); if (target.isFlavored()) { if (description instanceof Flavored) { if (!((Flavored) description).hasFlavors(ImmutableSet.copyOf(target.getFlavors()))) { throw UnexpectedFlavorException.createWithSuggestions(cell, target); }/* www . j a v a 2 s .c om*/ } else { LOG.warn( "Target %s (type %s) must implement the Flavored interface " + "before we can check if it supports flavors: %s", unflavoredBuildTarget, buildRuleType, target.getFlavors()); throw new HumanReadableException( "Target %s (type %s) does not currently support flavors (tried %s)", unflavoredBuildTarget, buildRuleType, target.getFlavors()); } } UnflavoredBuildTarget unflavoredBuildTargetFromRawData = RawNodeParsePipeline .parseBuildTargetFromRawRule(cell.getRoot(), rawNode, buildFile); if (!unflavoredBuildTarget.equals(unflavoredBuildTargetFromRawData)) { throw new IllegalStateException( String.format("Inconsistent internal state, target from data: %s, expected: %s, raw data: %s", unflavoredBuildTargetFromRawData, unflavoredBuildTarget, Joiner.on(',').withKeyValueSeparator("->").join(rawNode))); } Cell targetCell = cell.getCell(target); Object constructorArg = description.createUnpopulatedConstructorArg(); try { ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder(); ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder(); try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("MarshalledConstructorArg"))) { marshaller.populate(targetCell.getCellPathResolver(), targetCell.getFilesystem(), target, constructorArg, declaredDeps, visibilityPatterns, rawNode); } try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("CreatedTargetNode"))) { Hasher hasher = Hashing.sha1().newHasher(); hasher.putString(BuckVersion.getVersion(), UTF_8); JsonObjectHashing.hashJsonObject(hasher, rawNode); TargetNode<?, ?> node = targetNodeFactory.createFromObject(hasher.hash(), description, constructorArg, targetCell.getFilesystem(), target, declaredDeps.build(), visibilityPatterns.build(), targetCell.getCellPathResolver()); if (buildFileTrees.isPresent() && cell.isEnforcingBuckPackageBoundaries(target.getBasePath())) { enforceBuckPackageBoundaries(target, buildFileTrees.get().getUnchecked(targetCell), node.getInputs()); } nodeListener.onCreate(buildFile, node); return node; } } catch (NoSuchBuildTargetException e) { throw new HumanReadableException(e); } catch (ParamInfoException e) { throw new HumanReadableException("%s: %s", target, e.getMessage()); } catch (IOException e) { throw new HumanReadableException(e.getMessage(), e); } }
From source file:com.android.build.gradle.tasks.JillTask.java
/** * Returns a unique File for the converted library, even if there are 2 libraries with the same * file names (but different paths)//from w ww . ja v a 2 s.c om * * @param outFolder the output folder. * @param inputFile the library */ @NonNull public static File getJackFileName(@NonNull File outFolder, @NonNull File inputFile) { // get the filename String name = inputFile.getName(); // remove the extension int pos = name.lastIndexOf('.'); if (pos != -1) { name = name.substring(0, pos); } // add a hash of the original file path. String input = inputFile.getAbsolutePath(); HashFunction hashFunction = Hashing.sha1(); HashCode hashCode = hashFunction.hashString(input, Charsets.UTF_16LE); return new File(outFolder, name + "-" + hashCode.toString() + SdkConstants.DOT_JAR); }
From source file:com.android.build.gradle.internal.pipeline.OriginalStream.java
@NonNull private static String getUniqueInputName(@NonNull File file) { return Hashing.sha1().hashString(file.getPath(), Charsets.UTF_16LE).toString(); }
From source file:org.sonatype.nexus.rapture.internal.ui.StateComponent.java
public static boolean shouldSend(final String key, final Object value) { boolean shouldSend = true; if (WebContextManager.isWebContextAttachedToCurrentThread()) { HttpSession session = WebContextManager.get().getRequest().getSession(false); if (session != null) { String sessionAttribute = "state-digest-" + key; String currentDigest = (String) session.getAttribute(sessionAttribute); String newDigest = null; if (value != null) { // TODO is there another way to not use serialized json? :D newDigest = Hashing.sha1().hashString(gson.toJson(value), Charsets.UTF_8).toString(); }/*from w w w.j ava 2 s. co m*/ if (ObjectUtils.equals(currentDigest, newDigest)) { shouldSend = false; } else { if (newDigest != null) { session.setAttribute(sessionAttribute, newDigest); } else { session.removeAttribute(sessionAttribute); } } } } return shouldSend; }
From source file:org.glowroot.agent.model.QueryCollector.java
public void mergeQueriesInto(org.glowroot.common.model.QueryCollector collector) { for (Map.Entry<String, Map<String, MutableQuery>> outerEntry : queries.entrySet()) { for (Map.Entry<String, MutableQuery> entry : outerEntry.getValue().entrySet()) { String fullQueryText = entry.getKey(); String truncatedQueryText; String fullQueryTextSha1; if (fullQueryText.length() > Constants.AGGREGATE_QUERY_TEXT_TRUNCATE) { truncatedQueryText = fullQueryText.substring(0, Constants.AGGREGATE_QUERY_TEXT_TRUNCATE); fullQueryTextSha1 = Hashing.sha1().hashString(fullQueryText, UTF_8).toString(); } else { truncatedQueryText = fullQueryText; fullQueryTextSha1 = null; }//from w w w.j a v a 2 s . c o m MutableQuery query = entry.getValue(); collector.mergeQuery(outerEntry.getKey(), truncatedQueryText, fullQueryTextSha1, query.getTotalDurationNanos(), query.getExecutionCount(), query.hasTotalRows(), query.getTotalRows()); } } for (Map.Entry<String, MutableQuery> limitExceededBucket : limitExceededBuckets.entrySet()) { MutableQuery query = limitExceededBucket.getValue(); collector.mergeQuery(limitExceededBucket.getKey(), LIMIT_EXCEEDED_BUCKET, null, query.getTotalDurationNanos(), query.getExecutionCount(), query.hasTotalRows(), query.getTotalRows()); } }
From source file:org.macgyver.mercator.ucs.UCSScanner.java
protected void recordFabricInterconnect(Element element) { ObjectNode n = toJson(element);//from w ww. j a v a 2 s. co m if (n.path("model").asText().toUpperCase().startsWith("UCS-FI-")) { String serial = n.get("serial").asText(); String mercatorId = Hashing.sha1().hashString(serial, Charsets.UTF_8).toString(); n.put("mercatorId", mercatorId); String cypher = "merge (c:UCSFabricInterconnect {mercatorId:{mercatorId}}) set c+={props}, c.updateTs=timestamp()"; getProjector().getNeoRxClient().execCypher(cypher, "mercatorId", mercatorId, "props", n); cypher = "match (m:UCSManager {mercatorId:{managerId}}), (c:UCSFabricInterconnect {mercatorId:{fiId}}) merge (m)-[r:MANAGES]->(c) set r.updateTs=timestamp()"; getProjector().getNeoRxClient().execCypher(cypher, "managerId", getUCSClient().getUCSManagerId(), "fiId", mercatorId); } }
From source file:com.codenvy.dto.generator.DtoGenerator.java
private static String getApiHash(String packageName) throws IOException { byte[] fileBytes = packageName.getBytes(); HashCode hashCode = Hashing.sha1().hashBytes(fileBytes); return hashCode.toString(); }
From source file:com.facebook.buck.android.DexProducedFromJavaLibrary.java
@VisibleForTesting static Sha1HashCode computeAbiKey(ImmutableSortedMap<String, HashCode> classNames) { Hasher hasher = Hashing.sha1().newHasher(); for (Map.Entry<String, HashCode> entry : classNames.entrySet()) { hasher.putUnencodedChars(entry.getKey()); hasher.putByte((byte) 0); hasher.putUnencodedChars(entry.getValue().toString()); hasher.putByte((byte) 0); }//from w w w . ja va2 s .c o m return new Sha1HashCode(hasher.hash().toString()); }
From source file:com.android.build.gradle.tasks.PreDex.java
/** * Returns a unique File for the pre-dexed library, even * if there are 2 libraries with the same file names (but different * paths)/*from w w w . ja v a 2 s . c o m*/ * * If multidex is enabled the return File is actually a folder. * * @param outFolder the output folder. * @param inputFile the library. */ @NonNull static File getDexFileName(@NonNull File outFolder, @NonNull File inputFile) { // get the filename String name = inputFile.getName(); // remove the extension int pos = name.lastIndexOf('.'); if (pos != -1) { name = name.substring(0, pos); } // add a hash of the original file path. String input = inputFile.getAbsolutePath(); HashFunction hashFunction = Hashing.sha1(); HashCode hashCode = hashFunction.hashString(input, Charsets.UTF_16LE); return new File(outFolder, name + "-" + hashCode.toString() + SdkConstants.DOT_JAR); }