Not very elegant, but works
public static String binaryToHex(String bin) {
String hex = Long.toHexString(Long.parseLong(bin, 2));
return String.format("%" + (int)(Math.ceil(bin.length() / 4.0)) + "s", hex).replace(' ', '0');
}
I've used String.format() to left pad string with whitespaces then called replace() to replace it with zeros.