public static String createHash ( final InputStream inputStream , final String algorithm ) { checkNotNull ( "inputStream" , inputStream ) ; checkNotNull ( "algorithm" , algorithm ) ; try { final MessageDigest messageDigest = MessageDigest . getInstance ( algorithm ) ; try ( final BufferedInputStream in = new BufferedInputStream ( inputStream ) ) { final byte [ ] buf = new byte [ 1024 ] ; int count = 0 ; while ( ( count = in . read ( buf ) ) > - 1 ) { messageDigest . update ( buf , 0 , count ) ; } } return encodeHex ( messageDigest . digest ( ) ) ; } catch ( final NoSuchAlgorithmException | IOException ex ) { throw new RuntimeException ( ex ) ; } }
Creates a HEX encoded hash from a stream .