public static String checksum ( InputStream is ) { try { MessageDigest md = MessageDigest . getInstance ( "SHA1" ) ; byte [ ] dataBytes = new byte [ 1024 ] ; int nread ; while ( ( nread = is . read ( dataBytes ) ) != - 1 ) { md . update ( dataBytes , 0 , nread ) ; } byte [ ] mdbytes = md . digest ( ) ; S . Buffer sb = S . buffer ( ) ; for ( int i = 0 ; i < mdbytes . length ; i ++ ) { sb . append ( Integer . toString ( ( mdbytes [ i ] & 0xff ) + 0x100 , 16 ) . substring ( 1 ) ) ; } return sb . toString ( ) ; } catch ( NoSuchAlgorithmException e ) { throw E . unexpected ( "SHA1 algorithm not found" ) ; } catch ( IOException e ) { throw E . ioException ( e ) ; } }
Returns checksum from an input stream .