/** * 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); } }
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()); }
digest = Files.hash(file, algorithm.getFunction()).toString(); } catch (IOException ex) { GlowServer.logger.log(Level.SEVERE,
.contentMD5(Files.hash( ephemeral, Hashing.md5() )) .contentType("application/json");
.contentMD5(Files.hash( uploadFile, Hashing.md5())) .contentType( "application/json" );
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); } } }
/** * 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(); }
private static String md5(File file) { try { return Files.hash(file, Hashing.md5()).toString(); } catch (IOException e) { return ""; } }
public static String generateMD5(File f) { try { HashCode md5 = Files.hash(f, Hashing.md5()); return md5.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
public static String generateMD5(File f) { try { HashCode md5 = Files.hash(f, Hashing.md5()); return md5.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
public static String generateMD5(File f) { try { HashCode md5 = Files.hash(f, Hashing.md5()); return md5.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
public static String sha2FileChecksum(File file) { HashCode hc = null; try { hc = Files.hash(file, Hashing.sha256()); } catch (IOException e) { e.printStackTrace(); } return hc.toString(); }
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; }
public static String fileSHA (File file) throws IOException { if (file.exists()) { return Files.hash(file, Hashing.sha1()).toString(); } else { return ""; } }
/** * 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()); } }
/** * 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(); }
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"); }
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"); }
@Nullable private static HashCode getHash(@NonNull File file) { try { return Files.hash(file, Hashing.sha1()); } catch (IOException ignored) { } return null; }
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()); }