@Test public void testArrayOffset() { byte[] str = new byte[8]; Arrays.fill(str, (byte) '-'); int len = FastFormat.toZeroPaddedString(str, 4, 64L, 1, 16, new byte[] {}); assertEquals(2, len); assertEquals("----40--", new String(str, UTF_8)); Arrays.fill(str, (byte) '-'); len = FastFormat.toZeroPaddedString(str, 4, 64L, 2, 16, new byte[] {}); assertEquals(2, len); assertEquals("----40--", new String(str, UTF_8)); Arrays.fill(str, (byte) '-'); len = FastFormat.toZeroPaddedString(str, 4, 64L, 3, 16, new byte[] {}); assertEquals(3, len); assertEquals("----040-", new String(str, UTF_8)); Arrays.fill(str, (byte) '-'); len = FastFormat.toZeroPaddedString(str, 4, 64L, 1, 16, new byte[] {'P'}); assertEquals(3, len); assertEquals("----P40-", new String(str, UTF_8)); Arrays.fill(str, (byte) '-'); len = FastFormat.toZeroPaddedString(str, 4, 64L, 2, 16, new byte[] {'P'}); assertEquals(3, len); assertEquals("----P40-", new String(str, UTF_8)); Arrays.fill(str, (byte) '-'); len = FastFormat.toZeroPaddedString(str, 4, 64L, 3, 16, new byte[] {'P'}); assertEquals(4, len); assertEquals("----P040", new String(str, UTF_8)); Arrays.fill(str, (byte) '-'); len = FastFormat.toZeroPaddedString(str, 2, 64L, 4, 16, new byte[] {'P'}); assertEquals(5, len); assertEquals("--P0040-", new String(str, 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);  }