// generate a hex representation from the md5 of a byte-array
return encodeHex(encodeMD5Raw(b));
}
public static byte[] encodeMD5Raw(final String key) {
MessageDigest digest = null;
boolean fromPool = true;
if (digestPool.size() == 0) {
// if there are no digest objects left, create some on the fly
// this is not the most effective way but if we wouldn't do that the encoder would block
try {
digest = MessageDigest.getInstance("MD5");
digest.reset();
fromPool = false;
} catch (final NoSuchAlgorithmException e) {
}
}
if (digest == null) try {
digest = digestPool.take();
} catch (final InterruptedException e) {
Log.logWarning("Digest", "using generic instead of pooled digest");
try {
digest = MessageDigest.getInstance("MD5");
} catch (final NoSuchAlgorithmException e1) {
Log.logException(e1);
}
digest.reset();
fromPool = false;
}
byte[] keyBytes;
keyBytes = UTF8.getBytes(key);
digest.update(keyBytes);
final byte[] result = digest.digest();
digest.reset();
if (fromPool) {
returntopool: while (true) {
try {
digestPool.put(digest);
break returntopool;