List of usage examples for com.google.common.hash Hashing sha1
public static HashFunction sha1()
From source file:org.metaservice.core.file.FileUriUtils.java
public static FileIdentifier storeFile(InputStream inputStream) throws FileProcessingException { try {/* ww w. j a v a2 s.co m*/ File localDir = com.google.common.io.Files.createTempDir(); File localFile = new File(localDir.toString() + "/x"); IOUtils.copy(inputStream, new FileOutputStream(localFile)); HashCode x = com.google.common.io.Files.hash(localFile, Hashing.sha1()); long size = localFile.length(); Path target = getFile(x.toString(), size); Files.createDirectories(target.getParent()); Files.move(localFile.toPath(), target); return new FileIdentifier(x.toString(), size); } catch (IOException e) { throw new FileProcessingException(e); } }
From source file:com.facebook.buck.rules.Sha1HashCode.java
public static Sha1HashCode fromHashCode(HashCode hashCode) { Preconditions.checkNotNull(hashCode); return new Sha1HashCode(Hashing.sha1().newHasher().putBytes(hashCode.asBytes()).hash().toString()); }
From source file:com.facebook.buck.rules.keys.UncachedRuleKeyBuilder.java
private static RuleKeyHasher<HashCode> createHasher() { return new GuavaRuleKeyHasher(Hashing.sha1().newHasher()); }
From source file:org.lendingclub.mercator.solarwinds.SolarwindsScannerBuilder.java
public SolarwindsScannerBuilder withUrl(String url) { this.url = url; this.hashURL = Hashing.sha1().hashString(url, Charsets.UTF_8).toString(); return this; }
From source file:ome.util.checksum.SHA1ChecksumProviderImpl.java
public SHA1ChecksumProviderImpl() { super(Hashing.sha1()); }
From source file:org.elasticsearch.plugin.readonlyrest.acl.blocks.rules.impl.AuthKeySha1SyncRule.java
@Override protected HashFunction getHashFunction() { return Hashing.sha1(); }
From source file:net.sourceforge.fenixedu.domain.ExternalUser.java
private String hash(final String password) { return Hashing.sha1().hashString(password, Charsets.UTF_8).toString(); }
From source file:net.sourceforge.fenixedu.domain.onlineTests.StudentTestLog.java
public static String getChecksum(DistributedTest distributedTest, Registration student, DateTime dateTime) { StringBuilder checksumCode = new StringBuilder(); checksumCode.append(student.getNumber()); checksumCode.append(distributedTest.getExternalId()); final DateTime thisDateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute(), 0); checksumCode.append(thisDateTime.getMillis()); checksumCode.append(Bennu.getInstance().getTestChecksumsSet().iterator().next().getChecksumCode()); return (Hashing.sha1().hashString(checksumCode.toString(), Charsets.UTF_8)).toString(); }
From source file:io.macgyver.core.resource.StringResource.java
@Override public String getHash() throws IOException { return Hashing.sha1().hashString(value, Charset.defaultCharset()).toString(); }
From source file:com.facebook.buck.ide.intellij.StringTemplateFile.java
public static void writeToFile(ProjectFilesystem projectFilesystem, ST contents, Path path) throws IOException { StringWriter stringWriter = new StringWriter(); AutoIndentWriter noIndentWriter = new AutoIndentWriter(stringWriter); contents.write(noIndentWriter);//ww w. j a v a 2 s .c o m byte[] renderedContentsBytes = noIndentWriter.toString().getBytes(StandardCharsets.UTF_8); if (projectFilesystem.exists(path)) { Sha1HashCode fileSha1 = projectFilesystem.computeSha1(path); Sha1HashCode contentsSha1 = Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(renderedContentsBytes)); if (fileSha1.equals(contentsSha1)) { return; } } boolean danglingTempFile = false; Path tempFile = projectFilesystem.createTempFile(IjProjectPaths.IDEA_CONFIG_DIR, path.getFileName().toString(), ".tmp"); try { danglingTempFile = true; try (OutputStream outputStream = projectFilesystem.newFileOutputStream(tempFile)) { outputStream.write(contents.render().getBytes()); } projectFilesystem.createParentDirs(path); projectFilesystem.move(tempFile, path, StandardCopyOption.REPLACE_EXISTING); danglingTempFile = false; } finally { if (danglingTempFile) { projectFilesystem.deleteFileAtPath(tempFile); } } }