@Test public void getSha1Hash() throws IOException { File file = File.createTempFile("foo", "bar"); String hash = FileUtil.getSha1Hash(file); assertEquals("DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", hash); }
public static String getSha1Hash(File file) { InputStream fileInputStream = null; try { MessageDigest hash = MessageDigest.getInstance("SHA1"); fileInputStream = new BufferedInputStream(new FileInputStream(file)); DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, hash); byte[] buffer = new byte[8192]; while (digestInputStream.read(buffer, 0, buffer.length) != -1) { } byte[] sha1 = hash.digest(); return BitUtil.toHexString(sha1); } catch (NoSuchAlgorithmException nsae) { throw new AssertionError(nsae); } catch (FileNotFoundException fnfe) { throw new AssertionError(fnfe); } catch (IOException ioe) { Output.print(ioe); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException ioe) { throw new AssertionError(ioe); } } throw new AssertionError(); }
FileUtil { public static String getSha1Hash(File file) { InputStream fileInputStream = null; try { MessageDigest hash = MessageDigest.getInstance("SHA1"); fileInputStream = new BufferedInputStream(new FileInputStream(file)); DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, hash); byte[] buffer = new byte[8192]; while (digestInputStream.read(buffer, 0, buffer.length) != -1) { } byte[] sha1 = hash.digest(); return BitUtil.toHexString(sha1); } catch (NoSuchAlgorithmException nsae) { throw new AssertionError(nsae); } catch (FileNotFoundException fnfe) { throw new AssertionError(fnfe); } catch (IOException ioe) { Output.print(ioe); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException ioe) { throw new AssertionError(ioe); } } throw new AssertionError(); } }
FileUtil { public static String getSha1Hash(File file) { InputStream fileInputStream = null; try { MessageDigest hash = MessageDigest.getInstance("SHA1"); fileInputStream = new BufferedInputStream(new FileInputStream(file)); DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, hash); byte[] buffer = new byte[8192]; while (digestInputStream.read(buffer, 0, buffer.length) != -1) { } byte[] sha1 = hash.digest(); return BitUtil.toHexString(sha1); } catch (NoSuchAlgorithmException nsae) { throw new AssertionError(nsae); } catch (FileNotFoundException fnfe) { throw new AssertionError(fnfe); } catch (IOException ioe) { Output.print(ioe); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException ioe) { throw new AssertionError(ioe); } } throw new AssertionError(); } private  FileUtil(); }
FileUtil { public static String getSha1Hash(File file) { InputStream fileInputStream = null; try { MessageDigest hash = MessageDigest.getInstance("SHA1"); fileInputStream = new BufferedInputStream(new FileInputStream(file)); DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, hash); byte[] buffer = new byte[8192]; while (digestInputStream.read(buffer, 0, buffer.length) != -1) { } byte[] sha1 = hash.digest(); return BitUtil.toHexString(sha1); } catch (NoSuchAlgorithmException nsae) { throw new AssertionError(nsae); } catch (FileNotFoundException fnfe) { throw new AssertionError(fnfe); } catch (IOException ioe) { Output.print(ioe); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException ioe) { throw new AssertionError(ioe); } } throw new AssertionError(); } private  FileUtil(); static boolean copyDir(File fromDir, File toDir); static boolean copyDir(File fromDir, File toDir, FilenameFilter excluding); static boolean copy(File from, File to); static boolean copy(URL from, File to); static boolean copy(InputStream from, File to); static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName); static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF); static URL getUrl(String path); static InputStream downloadToStream(URL remoteUrl, Map<String, String> headers); static String pathFromParts(String ... parts); static File fromParts(String ... parts); static String resolveUnixTilde(String path); static String reverseUnixTilde(String path); static boolean isLocalPath(String path); static String encodeForURI(String filePath); static void delete(File file); static String getCanonicalPath(File file); static String stripFileUriPrefix(String path); static String getSha1Hash(File file); }
FileUtil { public static String getSha1Hash(File file) { InputStream fileInputStream = null; try { MessageDigest hash = MessageDigest.getInstance("SHA1"); fileInputStream = new BufferedInputStream(new FileInputStream(file)); DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, hash); byte[] buffer = new byte[8192]; while (digestInputStream.read(buffer, 0, buffer.length) != -1) { } byte[] sha1 = hash.digest(); return BitUtil.toHexString(sha1); } catch (NoSuchAlgorithmException nsae) { throw new AssertionError(nsae); } catch (FileNotFoundException fnfe) { throw new AssertionError(fnfe); } catch (IOException ioe) { Output.print(ioe); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException ioe) { throw new AssertionError(ioe); } } throw new AssertionError(); } private  FileUtil(); static boolean copyDir(File fromDir, File toDir); static boolean copyDir(File fromDir, File toDir, FilenameFilter excluding); static boolean copy(File from, File to); static boolean copy(URL from, File to); static boolean copy(InputStream from, File to); static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName); static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF); static URL getUrl(String path); static InputStream downloadToStream(URL remoteUrl, Map<String, String> headers); static String pathFromParts(String ... parts); static File fromParts(String ... parts); static String resolveUnixTilde(String path); static String reverseUnixTilde(String path); static boolean isLocalPath(String path); static String encodeForURI(String filePath); static void delete(File file); static String getCanonicalPath(File file); static String stripFileUriPrefix(String path); static String getSha1Hash(File file);  }