public static String computeHash ( final InternalResource resource ) { final int bufferSize = 1024 ; try ( InputStream stream = resource . getStream ( ) ) { if ( stream == null ) { return null ; } // Compute CRC-32 checksum // TODO: Is a 1 in 2^32 chance of a cache bust fail good enough? // Checksum checksumEngine = new Adler32(); Checksum checksumEngine = new CRC32 ( ) ; byte [ ] buf = new byte [ bufferSize ] ; for ( int read = stream . read ( buf ) ; read != - 1 ; read = stream . read ( buf ) ) { checksumEngine . update ( buf , 0 , read ) ; } return Long . toHexString ( checksumEngine . getValue ( ) ) ; } catch ( Exception e ) { throw new SystemException ( "Error calculating resource hash" , e ) ; } }
Computes a simple hash of the resource contents .