tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject MD5Encoder.encode versus HexUtils.toHexString
Date Sat, 15 Jun 2013 15:39:48 GMT

While looking into a patch for BasicRealm, I noticed that there are two
classes that convert byte[] to a hex-encoded string (e.g. byte[] { 1, 2,
a, b ] -> "12ab"): HexUtils and MD5Encoder.

MD5Encoder only has a single method (encode) and it does exactly what
HexUtils.toHexString does, except that it only works for exactly 16-byte

I haven't actually written any performance tests, but looking at the
code it seems that HexUtils.toHexString would execute slightly faster
for a 16-byte array because of repeated integer multiplication in the loop.

Is there a reason for MD5Encoder to exist? It appears only to be used in
the following classes:


Although I suppose a specialty 16-byte-only method might be written to
be slightly faster than the general-purpose HexUtils.toHexString method,
I'm not sure it's worth having a separate class/method to do it.

Any objections to using HexUtils.toHexString uniformly and removing the
MD5Encoder class entirely?


View raw message