@Test public void testFormat() { assertEquals("100", new String(FastFormat.toZeroPaddedString(1296, 1, 36, new byte[] {}), UTF_8)); assertEquals("100", new String(FastFormat.toZeroPaddedString(1296, 2, 36, new byte[] {}), UTF_8)); assertEquals("100", new String(FastFormat.toZeroPaddedString(1296, 3, 36, new byte[] {}), UTF_8)); assertEquals("0100", new String(FastFormat.toZeroPaddedString(1296, 4, 36, new byte[] {}), UTF_8)); assertEquals("00100", new String(FastFormat.toZeroPaddedString(1296, 5, 36, new byte[] {}), UTF_8)); assertEquals("PA100", new String(FastFormat.toZeroPaddedString(1296, 1, 36, new byte[] {'P', 'A'}), UTF_8)); assertEquals("PA100", new String(FastFormat.toZeroPaddedString(1296, 2, 36, new byte[] {'P', 'A'}), UTF_8)); assertEquals("PA100", new String(FastFormat.toZeroPaddedString(1296, 3, 36, new byte[] {'P', 'A'}), UTF_8)); assertEquals("PA0100", new String(FastFormat.toZeroPaddedString(1296, 4, 36, new byte[] {'P', 'A'}), UTF_8)); assertEquals("PA00100", new String(FastFormat.toZeroPaddedString(1296, 5, 36, new byte[] {'P', 'A'}), UTF_8)); assertEquals("PA000100", new String(FastFormat.toZeroPaddedString(1296, 6, 36, new byte[] {'P', 'A'}), UTF_8)); assertEquals("PA0000100", new String(FastFormat.toZeroPaddedString(1296, 7, 36, new byte[] {'P', 'A'}), UTF_8)); }
public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { Preconditions.checkArgument(num >= 0); String strNum = Long.toString(num, radix); byte[] ret = new byte[Math.max(strNum.length(), width) + prefix.length]; if (toZeroPaddedString(ret, 0, strNum, width, prefix) != ret.length) throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, UTF_8)); return ret; }
FastFormat { public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { Preconditions.checkArgument(num >= 0); String strNum = Long.toString(num, radix); byte[] ret = new byte[Math.max(strNum.length(), width) + prefix.length]; if (toZeroPaddedString(ret, 0, strNum, width, prefix) != ret.length) throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, UTF_8)); return ret; } }
FastFormat { public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { Preconditions.checkArgument(num >= 0); String strNum = Long.toString(num, radix); byte[] ret = new byte[Math.max(strNum.length(), width) + prefix.length]; if (toZeroPaddedString(ret, 0, strNum, width, prefix) != ret.length) throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, UTF_8)); return ret; }  }
FastFormat { public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { Preconditions.checkArgument(num >= 0); String strNum = Long.toString(num, radix); byte[] ret = new byte[Math.max(strNum.length(), width) + prefix.length]; if (toZeroPaddedString(ret, 0, strNum, width, prefix) != ret.length) throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, UTF_8)); return ret; }  static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix); static int toZeroPaddedString(byte[] output, int outputOffset, long num, int width,
      int radix, byte[] prefix); }
FastFormat { public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { Preconditions.checkArgument(num >= 0); String strNum = Long.toString(num, radix); byte[] ret = new byte[Math.max(strNum.length(), width) + prefix.length]; if (toZeroPaddedString(ret, 0, strNum, width, prefix) != ret.length) throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, UTF_8)); return ret; }  static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix); static int toZeroPaddedString(byte[] output, int outputOffset, long num, int width,
      int radix, byte[] prefix);  }