List of usage examples for com.google.common.hash Hashing sha1
public static HashFunction sha1()
From source file:org.grouplens.lenskit.util.io.Descriptions.java
/** * Create a description writer that will compute a SHA1 hash. * * @return A description writer computing a SHA1 hash. *//*w w w . jav a 2s . c o m*/ public static HashDescriptionWriter sha1Writer() { return hashWriter(Hashing.sha1()); }
From source file:com.facebook.buck.cxx.LcUuidScrubber.java
@Override public void scrubFile(FileChannel file) throws IOException, ScrubException { if (!Machos.isMacho(file)) { return;/*from w w w. j a v a 2 s. co m*/ } long size = file.size(); MappedByteBuffer map = file.map(FileChannel.MapMode.READ_WRITE, 0, size); try { Machos.setUuid(map, ZERO_UUID); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } map.rewind(); Hasher hasher = Hashing.sha1().newHasher(); while (map.hasRemaining()) { hasher.putByte(map.get()); } map.rewind(); try { Machos.setUuid(map, Arrays.copyOf(hasher.hash().asBytes(), 16)); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } }
From source file:com.android.sdklib.repository.License.java
public License(@NonNull String license, @Nullable String licenseRef) { mLicense = license; mLicenseRef = licenseRef; mLicenseHash = Hashing.sha1().hashBytes(mLicense.getBytes()).toString(); }
From source file:com.facebook.buck.cxx.toolchain.objectfile.LcUuidContentsScrubber.java
@Override public void scrubFile(FileChannel file) throws IOException, ScrubException { if (!Machos.isMacho(file)) { return;// ww w . j av a 2 s. com } long size = file.size(); MappedByteBuffer map = file.map(FileChannel.MapMode.READ_WRITE, 0, size); try { Machos.setUuidIfPresent(map, ZERO_UUID); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } map.rewind(); Hasher hasher = Hashing.sha1().newHasher(); while (map.hasRemaining()) { hasher.putByte(map.get()); } map.rewind(); try { Machos.setUuidIfPresent(map, Arrays.copyOf(hasher.hash().asBytes(), 16)); } catch (Machos.MachoException e) { throw new ScrubException(e.getMessage()); } }
From source file:com.facebook.buck.file.FileHash.java
/** Get the hash function for this type of hash */ public HashFunction getHashFunction() { if (sha1OrSha256.isLeft()) { return Hashing.sha1(); } else {//from w w w .j a v a 2 s . co m return Hashing.sha256(); } }
From source file:com.google.gerrit.server.util.RequestId.java
private RequestId(String resourceId) { Hasher h = Hashing.sha1().newHasher(); h.putLong(Thread.currentThread().getId()).putUnencodedChars(MACHINE_ID); str = "[" + resourceId + "-" + TimeUtil.nowTs().getTime() + "-" + h.hash().toString().substring(0, 8) + "]"; }
From source file:io.macgyver.core.resource.provider.filesystem.FileSystemResource.java
@Override public String getHash() throws IOException { return Files.hash(fileObject, Hashing.sha1()).toString(); }
From source file:com.facebook.buck.features.project.intellij.StringTemplateFile.java
public static boolean writeToFile(ProjectFilesystem projectFilesystem, ST contents, Path path, Path ideaConfigDir) throws IOException { byte[] renderedContentsBytes = contents.render().getBytes(); projectFilesystem.createParentDirs(path); if (projectFilesystem.exists(path)) { Sha1HashCode fileSha1 = projectFilesystem.computeSha1(path); Sha1HashCode contentsSha1 = Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(renderedContentsBytes)); if (fileSha1.equals(contentsSha1)) { return false; }//from www .ja va2 s. c o m boolean danglingTempFile = false; Path tempFile = projectFilesystem.createTempFile(ideaConfigDir, path.getFileName().toString(), ".tmp"); try { danglingTempFile = true; try (OutputStream outputStream = projectFilesystem.newFileOutputStream(tempFile)) { outputStream.write(renderedContentsBytes); } projectFilesystem.move(tempFile, path, StandardCopyOption.REPLACE_EXISTING); danglingTempFile = false; } finally { if (danglingTempFile) { projectFilesystem.deleteFileAtPath(tempFile); } } } else { try (OutputStream outputStream = projectFilesystem.newFileOutputStream(path)) { outputStream.write(renderedContentsBytes); } } return true; }
From source file:com.eventsourcing.h2.index.UniqueIndex.java
public static <A, O extends Entity> UniqueIndex<A, O> onAttribute(MVStore store, Attribute<O, A> attribute) { return onAttribute(store, attribute, Hashing.sha1()); }
From source file:minium.cucumber.report.domain.Embedding.java
@JsonInclude(Include.NON_NULL) public String getSha1Hash() { if (sha1Hash == null && data != null) { sha1Hash = Hashing.sha1().hashBytes(data).toString(); }// w w w . j a v a 2 s. c o m return sha1Hash; }