What is/are the Scala way(s) to implement this Java "byte[] to Hex" class
- by nicerobot
I'm specifically interested in Scala (2.8) techniques for building strings with formats as well as interesting ways to make such a capability easily accessible where it's useful (lists of bytes, String, ...?)..
public class Hex {
public static String valueOf (final byte buf[]) {
if (null == buf) {
return null;
}
final StringBuilder sb = new StringBuilder(buf.length * 2);
for (final byte b : buf) {
sb.append(String.format("%02X", b & 0xff));
}
return sb.toString();
}
public static String valueOf (final Byteable o) {
return valueOf(o.toByteArray());
}
}
This is only a learning exercise (so the utility and implementation of the Java isn't a concern.)
Thanks