ShortUtils { public static byte[] toByteArray(short value) { return toByteArray(value, 8); }  static byte[] toByteArray(short value); static byte[] toByteArray(short value, int numBits); static byte[] toByteArray(short value, int numBits, boolean bigEndian); static byte[] toByteArray(short value, boolean padArrayToTypeLength); static byte[] toByteArray(short value, boolean padArrayToTypeLength, boolean bigEndian);  }
@Test public void testToByteArray() { byte[] result = ShortUtils.toByteArray(Short.MAX_VALUE); byte[] expected = new byte[] { 0x7F, (byte) 0xFF }; assertEquals(expected, result); result = ShortUtils.toByteArray(Short.MAX_VALUE, true); expected = new byte[] { 0x7F, (byte) 0xFF }; assertEquals(expected, result); result = ShortUtils.toByteArray((short) 0, true); expected = new byte[] { 0x00, 0x00 }; assertEquals(expected, result); result = ShortUtils.toByteArray((short) 0, false); expected = new byte[] { 0x00 }; assertEquals(expected, result); result = ShortUtils.toByteArray((short) 0x9000); expected = new byte[] { (byte) 0x90, 0x00 }; assertEquals(expected, result); }