List of utility methods to do Formatter Usage
String | byteArrayToHexString(byte[] bytes, int pos, int len) Converts a byte array to hex string. StringBuilder sb = new StringBuilder(bytes.length * 2); Formatter formatter = new Formatter(sb); for (int i = pos; i < pos + len; ++i) { formatter.format("%02x", bytes[i]); return sb.toString(); |
String | bytesToHexString(byte[] bytes) bytes To Hex String StringBuilder sb = new StringBuilder(bytes.length * 2); Formatter formatter = new Formatter(sb); for (byte b : bytes) { formatter.format("%02x", b); formatter.close(); return sb.toString(); |
String | byteToHex(final byte[] bytes) byte To Hex Formatter formatter = new Formatter(); for (byte b : bytes) { formatter.format("%02x", b); String result = formatter.toString(); formatter.close(); return result; |
String | byteToHexWithPrefix(final byte[] data) Convert bytes to hex + 0x in front. return "0x" + byteToHex(data); |
boolean | chatting(String fmt, Object... args) Formatted output Formatter f = new Formatter(System.out); f.format(fmt, args); return true; |
String | convertRGBDecToHex(String decimal) Convert rgb dec to hex. String returnValue = null; Formatter formatter = null; formatter = new Formatter(); returnValue = "#" + formatter .format("%02x%02x%02x", Integer.parseInt(decimal.substring(0, 3)), Integer.parseInt(decimal.substring(3, 6)), Integer.parseInt(decimal.substring(6, 9))) .toString(); return returnValue; ... |
String | convertTimeToString(double d, String timeFormat) Converts time to string. StringBuilder sb = new StringBuilder(); try (Formatter formatter = new Formatter(sb, Locale.US)) { double s = d % 60; int h = (int) (d / 3600); int m = ((int) (d / 60)) % 60; formatter.format(timeFormat, h, m, s); return sb.toString(); ... |
String | convertToMillions(double tmp) convert To Millions StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); formatter.format("%12.6f mio", tmp / 1000. / 1000.); formatter.close(); return sb.toString(); |
String | createHexadecimalString(byte[] data) Creates the hexadecimal string encoding specified data. StringBuilder sb = new StringBuilder(data.length * 2); Formatter formatter = new Formatter(sb); for (byte b : data) { formatter.format("%02x", b); formatter.close(); return sb.toString(); |
String | digestToString(byte[] input) Creates a String from a MessageDigest result. Formatter formatter = new Formatter(); for (byte b : input) { formatter.format("%02x", b); return formatter.toString(); |