本文整理了Java中com.google.common.io.Files.hash()
方法的一些代码示例,展示了Files.hash()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.hash()
方法的具体详情如下:
包路径:com.google.common.io.Files
类名称:Files
方法名:hash
[英]Computes the hash code of the file using hashFunction.
[中]使用hashFunction计算文件的哈希代码。
代码示例来源:origin: Netflix/Priam
/**
* Calculate the MD5 hashsum of the given file.
*
* @param file File for which md5 checksum should be calculated.
* @return Get a Md5 string which is similar to OS Md5sum
*/
public static String md5(File file) {
try {
HashCode hc = Files.hash(file, Hashing.md5());
return toHex(hc.asBytes());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: google/guava
public void testHash() throws IOException {
File asciiFile = getTestFile("ascii.txt");
File i18nFile = getTestFile("i18n.txt");
String init = "d41d8cd98f00b204e9800998ecf8427e";
assertEquals(init, Hashing.md5().newHasher().hash().toString());
String asciiHash = "e5df5a39f2b8cb71b24e1d8038f93131";
assertEquals(asciiHash, Files.hash(asciiFile, Hashing.md5()).toString());
String i18nHash = "7fa826962ce2079c8334cd4ebf33aea4";
assertEquals(i18nHash, Files.hash(i18nFile, Hashing.md5()).toString());
}
代码示例来源:origin: GlowstoneMC/Glowstone
digest = Files.hash(file, algorithm.getFunction()).toString();
} catch (IOException ex) {
GlowServer.logger.log(Level.SEVERE,
代码示例来源:origin: apache/usergrid
.contentMD5(Files.hash( ephemeral, Hashing.md5() ))
.contentType("application/json");
代码示例来源:origin: apache/usergrid
.contentMD5(Files.hash( uploadFile, Hashing.md5()))
.contentType( "application/json" );
代码示例来源:origin: HubSpot/Singularity
private String calculateMd5sum(Path path) {
try {
HashCode hc = com.google.common.io.Files.hash(path.toFile(), Hashing.md5());
return hc.toString();
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
}
代码示例来源:origin: com.opera/operadriver
/**
* Get the MD5 hash of the given file.
*
* @param file file to compute a hash on
* @return a byte array of the MD5 hash
* @throws IOException if file cannot be found
*/
public static byte[] hash(File file) throws IOException {
return Files.hash(file, Hashing.md5()).asBytes();
}
代码示例来源:origin: classmethod/gradle-aws-plugin
private static String md5(File file) {
try {
return Files.hash(file, Hashing.md5()).toString();
} catch (IOException e) {
return "";
}
}
代码示例来源:origin: gradle.plugin.com.banderous.getpack/plugin
public static String generateMD5(File f) {
try {
HashCode md5 = Files.hash(f, Hashing.md5());
return md5.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: gradle.plugin.com.outlinegames/plugin
public static String generateMD5(File f) {
try {
HashCode md5 = Files.hash(f, Hashing.md5());
return md5.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: gradle.plugin.com.banderous.gpm/plugin
public static String generateMD5(File f) {
try {
HashCode md5 = Files.hash(f, Hashing.md5());
return md5.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: dessalines/torrenttunes-client
public static String sha2FileChecksum(File file) {
HashCode hc = null;
try {
hc = Files.hash(file, Hashing.sha256());
} catch (IOException e) {
e.printStackTrace();
}
return hc.toString();
}
代码示例来源:origin: scireum/s3ninja
private String getETag(File file) {
try {
return com.google.common.io.Files.hash(file, Hashing.md5()).toString();
} catch (IOException e) {
Exceptions.ignore(e);
}
return null;
}
代码示例来源:origin: Slowpoke101/FTBLaunch
public static String fileSHA (File file) throws IOException {
if (file.exists()) {
return Files.hash(file, Hashing.sha1()).toString();
} else {
return "";
}
}
代码示例来源:origin: REDNBLACK/J-Kinopoisk2IMDB
/**
* Returns SHA-256 hashcode of file.
*
* @param filePath File to calculate hashcode for
* @return File hashcode.
*/
public static String getFileHashCode(Path filePath) {
return ExceptionUtils.uncheck(() -> hash(filePath.toFile(), Hashing.sha256()).toString());
}
}
代码示例来源:origin: com.amazon.device.tools.build/gradle-core
/**
* Returns the hash of a file.
*
* @param file the file to hash
*/
private static String getFileHash(@NonNull File file) throws IOException {
HashCode hashCode = Files.hash(file, Hashing.sha1());
return hashCode.toString();
}
代码示例来源:origin: us.ihmc/IHMCRobotDataLogger
private void setChecksums(CompressionProperties properties) throws IOException
{
out.println("Saving checksums to file");
File logdata = new File(logDirectory, logProperties.getVariableDataFile());
properties.setDataChecksum(Files.hash(logdata, Hashing.sha1()).toString());
File index = new File(logDirectory, logProperties.getVariablesIndexFile());
properties.setTimestampChecksum(Files.hash(index, Hashing.sha1()).toString());
out.println("Saved checksums");
}
代码示例来源:origin: us.ihmc/ihmc-robot-data-visualizer
private void setChecksums(CompressionProperties properties) throws IOException
{
out.println("Saving checksums to file");
File logdata = new File(logDirectory, logProperties.getVariables().getDataAsString());
properties.setDataChecksum(Files.hash(logdata, Hashing.sha1()).toString());
File index = new File(logDirectory, logProperties.getVariables().getDataAsString());
properties.setTimestampChecksum(Files.hash(index, Hashing.sha1()).toString());
out.println("Saved checksums");
}
代码示例来源:origin: com.amazon.device.tools.build/builder
@Nullable
private static HashCode getHash(@NonNull File file) {
try {
return Files.hash(file, Hashing.sha1());
} catch (IOException ignored) {
}
return null;
}
代码示例来源:origin: com.google.guava/guava-tests
public void testHash() throws IOException {
File asciiFile = getTestFile("ascii.txt");
File i18nFile = getTestFile("i18n.txt");
String init = "d41d8cd98f00b204e9800998ecf8427e";
assertEquals(init, Hashing.md5().newHasher().hash().toString());
String asciiHash = "e5df5a39f2b8cb71b24e1d8038f93131";
assertEquals(asciiHash, Files.hash(asciiFile, Hashing.md5()).toString());
String i18nHash = "7fa826962ce2079c8334cd4ebf33aea4";
assertEquals(i18nHash, Files.hash(i18nFile, Hashing.md5()).toString());
}
内容来源于网络,如有侵权,请联系作者删除!