Permalink
Browse files

Merge pull request #195 from ahus1/2_0_x

Optimed MD5 calculation to be blockwise as bytewise operation is slow
  • Loading branch information...
2 parents a7e0d15 + ebf33a6 commit 239cd4f5c73a12cc508a3903bdabc923d299c413 @nvoxland nvoxland committed Oct 23, 2013
Showing with 6 additions and 5 deletions.
  1. +6 −5 liquibase-core/src/main/java/liquibase/util/MD5Util.java
View
11 liquibase-core/src/main/java/liquibase/util/MD5Util.java
@@ -34,7 +34,7 @@ public static String computeMD5(String input) {
byte[] digestBytes = digest.digest();
String returnString = new String(encodeHex(digestBytes));
- LogFactory.getLogger().debug("Computed checksum for "+input+" as "+returnString);
+ LogFactory.getLogger().debug("Computed checksum for " + input + " as " + returnString);
return returnString;
}
@@ -45,8 +45,9 @@ public static String computeMD5(InputStream stream) {
digest = MessageDigest.getInstance("MD5");
DigestInputStream digestStream = new DigestInputStream(stream, digest);
- while (digestStream.read() != -1) {
- ; //digest is updating
+ byte[] buf = new byte[20480];
+ while (digestStream.read(buf) != -1) {
+ ; // digest is updating
}
} catch (Exception e) {
throw new RuntimeException(e);
@@ -55,15 +56,15 @@ public static String computeMD5(InputStream stream) {
String returnString = new String(encodeHex(digestBytes));
- LogFactory.getLogger().debug("Computed checksum for "+returnString+" as "+returnString);
+ LogFactory.getLogger().debug("Computed checksum for " + returnString + " as " + returnString);
return returnString;
}
/**
* Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
* The returned array will be double the length of the passed array, as it takes two characters to represent any
* given byte.
- *
+ *
* @param data
* a byte[] to convert to Hex characters
* @return A char[] containing hexadecimal characters

0 comments on commit 239cd4f

Please sign in to comment.