IntegerUtils { public static byte[] toByteArray(int value) { return toByteArray(value, 8); }  static byte[] toByteArray(int value); static byte[] toByteArray(int value, int numBits); static byte[] toByteArray(int value, int numBits, boolean bigEndian); static byte[] toByteArray(int value, boolean padArrayToTypeLength); static byte[] toByteArray(int value, boolean padArrayToTypeLength, boolean bigEndian);  }
@Test public void testToByteArray() { byte[] expected = new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; assertEquals(expected, IntegerUtils.toByteArray(Integer.MAX_VALUE)); expected = new byte[] { 0x00 }; assertEquals(expected, IntegerUtils.toByteArray(0)); expected = new byte[] { 0x00, 0x00, 0x00, 0x00 }; assertEquals(expected, IntegerUtils.toByteArray(0, true)); expected = new byte[] { 0x00 }; assertEquals(expected, IntegerUtils.toByteArray(0, false)); expected = new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; assertEquals(expected, IntegerUtils.toByteArray(Integer.MAX_VALUE, true)); expected = new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; assertEquals(expected, IntegerUtils.toByteArray(Integer.MAX_VALUE, true)); expected = new byte[] { 0x01, 0x00, 0x00, 0x00 }; assertEquals(expected, IntegerUtils.toByteArray(8, 1)); expected = new byte[] { 0x03, 0x01 }; assertEquals(expected, IntegerUtils.toByteArray(0x61, 5)); }