List of usage examples for com.google.common.hash Hashing adler32
public static HashFunction adler32()
From source file:com.lithium.flow.util.HashFunctions.java
@Nonnull public static HashFunction of(@Nonnull String name) { checkNotNull(name);// ww w . ja v a 2s . c o m switch (name) { case "adler32": return Hashing.adler32(); case "crc32": return Hashing.crc32(); case "md5": return Hashing.md5(); case "sha1": return Hashing.sha1(); case "sha256": return Hashing.sha256(); case "sha512": return Hashing.sha512(); case "sipHash24": return Hashing.sipHash24(); case "murmur3_32": return Hashing.murmur3_32(); case "murmur3_128": return Hashing.murmur3_128(); default: throw new RuntimeException("unknown hash: " + name); } }
From source file:org.gradle.api.internal.file.FileTreeElementHasher.java
public static final int calculateHashForFilePaths(Collection<FileTreeElement> allFileTreeElements) { SortedSet<FileTreeElement> sortedFileTreeElement = asSortedSet(allFileTreeElements); Hasher hasher = Hashing.adler32().newHasher(); for (FileTreeElement fileTreeElement : sortedFileTreeElement) { for (String pathPart : fileTreeElement.getRelativePath().getSegments()) { hasher.putUnencodedChars(pathPart); hasher.putByte(HASH_PATH_SEPARATOR); }/*from w w w. j a va 2 s . c o m*/ hasher.putByte(HASH_RECORD_SEPARATOR); } return hasher.hash().asInt(); }
From source file:ome.util.checksum.Adler32ChecksumProviderImpl.java
public Adler32ChecksumProviderImpl() { super(Hashing.adler32()); }
From source file:io.github.maxymania.powercache.proxy.MethodCall.java
@Override public int hashCode() { //int hash = 7; //hash = 79 * hash + Objects.hashCode(this.name); //hash = 79 * hash + Arrays.deepHashCode(this.data); //return hash; Hasher h = Hashing.adler32().newHasher(); h.putString(name, Util.UTF);/*from w w w. j ava 2 s . c o m*/ h.putObject(data, Util.funnel); return h.hash().asInt(); }
From source file:org.knime.ext.textprocessing.nodes.transformation.documentvectorhashing.Adler32HashingFunction.java
/** * {@inheritDoc}/* w ww . ja v a 2s . c o m*/ */ @Override public int hash(final String term, final int seed) { HashFunction hash = Hashing.adler32(); HashCode hashCode = hash.hashString(term, Charsets.UTF_8); return hashCode.asInt(); }
From source file:org.lightjason.agentspeak.action.builtin.crypto.CHash.java
/** * runs hashing function with difference between Google Guava hashing and Java default digest * * @param p_context execution context//from w ww . j a v a 2s . c om * @param p_algorithm algorithm name * @param p_data byte data representation * @return hash value */ private static String hash(@Nonnull final IContext p_context, @Nonnull final String p_algorithm, @Nonnull final byte[] p_data) { switch (p_algorithm.trim().toLowerCase(Locale.ROOT)) { case "adler-32": return Hashing.adler32().newHasher().putBytes(p_data).hash().toString(); case "crc-32": return Hashing.crc32().newHasher().putBytes(p_data).hash().toString(); case "crc-32c": return Hashing.crc32c().newHasher().putBytes(p_data).hash().toString(); case "murmur3-32": return Hashing.murmur3_32().newHasher().putBytes(p_data).hash().toString(); case "murmur3-128": return Hashing.murmur3_128().newHasher().putBytes(p_data).hash().toString(); case "siphash-2-4": return Hashing.sipHash24().newHasher().putBytes(p_data).hash().toString(); default: try { return BaseEncoding.base16().encode(MessageDigest.getInstance(p_algorithm).digest(p_data)) .toLowerCase(Locale.ROOT); } catch (final NoSuchAlgorithmException l_exception) { throw new CRuntimeException(l_exception, p_context); } } }
From source file:org.lightjason.agentspeak.action.buildin.crypto.CHash.java
/** * runs hashing function with difference between Google Guava hashing and Java default digest * * @param p_algorithm algorithm name/*from w ww. j a va2 s. c o m*/ * @param p_data byte data representation * @return hash value * * @throws NoSuchAlgorithmException on unknown hashing algorithm */ private String hash(final String p_algorithm, final byte[] p_data) throws NoSuchAlgorithmException { switch (p_algorithm.trim().toLowerCase(Locale.ROOT)) { case "adler-32": return Hashing.adler32().newHasher().putBytes(p_data).hash().toString(); case "crc-32": return Hashing.crc32().newHasher().putBytes(p_data).hash().toString(); case "crc-32c": return Hashing.crc32c().newHasher().putBytes(p_data).hash().toString(); case "murmur3-32": return Hashing.murmur3_32().newHasher().putBytes(p_data).hash().toString(); case "murmur3-128": return Hashing.murmur3_128().newHasher().putBytes(p_data).hash().toString(); case "siphash-2-4": return Hashing.sipHash24().newHasher().putBytes(p_data).hash().toString(); default: return String.format("%032x", new BigInteger(1, MessageDigest.getInstance(p_algorithm).digest(p_data))); } }
From source file:org.dcache.xrootd.standalone.DataServerHandler.java
@Override protected QueryResponse doOnQuery(ChannelHandlerContext ctx, QueryRequest msg) throws XrootdException { switch (msg.getReqcode()) { case kXR_Qconfig: StringBuilder s = new StringBuilder(); for (String name : msg.getArgs().split(" ")) { switch (name) { case "bind_max": s.append(0);/*from ww w . j a v a 2 s . co m*/ break; case "readv_ior_max": s.append(MAX_FRAME_SIZE); break; case "readv_iov_max": s.append(Integer.MAX_VALUE); break; case "csname": s.append("1:ADLER32"); break; case "version": s.append("xrootd4j"); break; default: s.append(name); break; } s.append('\n'); } return new QueryResponse(msg, s.toString()); case kXR_Qcksum: try { HashCode hash = com.google.common.io.Files.asByteSource(getFile(msg.getArgs())) .hash(Hashing.adler32()); return new QueryResponse(msg, "ADLER32 " + hash); } catch (FileNotFoundException e) { throw new XrootdException(kXR_NotFound, e.getMessage()); } catch (IOException e) { throw new XrootdException(kXR_IOError, e.getMessage()); } default: throw new XrootdException(kXR_Unsupported, "Unsupported kXR_query reqcode: " + msg.getReqcode()); } }
From source file:org.brooth.jeta.apt.JetaProcessor.java
private String getUtdDirPath() { if ($utdDirPath != null) return $utdDirPath; $utdDirPath = properties.getProperty("utd.dir"); if ($utdDirPath != null) { Path path = Paths.get($utdDirPath); if (!path.isAbsolute()) path = Paths.get(relateToPath + $utdDirPath).toAbsolutePath(); $utdDirPath = path.normalize().toString(); } else {//from ww w .ja va 2 s . c om $utdDirPath = System.getProperty("java.io.tmpdir"); if (!$utdDirPath.endsWith(File.separator)) $utdDirPath += File.separator; $utdDirPath += "jeta-utd-files"; } if (!$utdDirPath.endsWith(File.separator)) $utdDirPath += File.separator; try { $utdDirPath += Hashing.adler32().newHasher() .putString(processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, "a", "b") .toUri().getPath(), Charset.defaultCharset()) .hash().toString() + File.separator; } catch (IOException e) { throw new ProcessingException("failed to get upt dir hash", e); } Path structurePath = Paths.get($utdDirPath); if (Files.notExists(structurePath) && !structurePath.toFile().mkdirs()) throw new ProcessingException("not valid utd.dir property", new IOException("failed to create utd.dir structure")); return $utdDirPath; }