ByteUtil { public static long packLongWithUnsignedShortInts(final int int1, final int int2, final int int3, final int int4) { checkUnsignedShort(int1); checkUnsignedShort(int2); checkUnsignedShort(int3); checkUnsignedShort(int4); return ((int1 & 0xFFFFL) << 48) + ((int2 & 0xFFFFL) << 32) + ((int3 & 0xFFFFL) << 16) + (int4 & 0xFFFFL); }  static void writeLongAsAscii(final byte[] outputBuffer, final int offset, final long valueParam); static boolean isAsciiDigit(final byte asciiCharacter); static String formatIntAsIpAddress(final int address); static void formatIntAsIpAddress(final StringBuilder buffer, final int address); static long packLongWithUnsignedShortInts(final int int1, final int int2, final int int3, final int int4); static boolean isEqual(final byte[] lhs, final int lhsOffset, final byte[] rhs, final int rhsOffset, final int length); static int readIntFromAscii(final byte[] asciiBuffer, final int offset, final int length); static long readLongFromAscii(final byte[] asciiBuffer, final int offset, final int length); static boolean isInteger(final byte[] asciiBuffer, final int offset, final int length); static void replace(final byte[] buffer, final int offset, final int length,
                               final byte target, final byte replacement); static void asciiEncode(final CharSequence chars, final int charOffset,
                                   final byte[] buffer, final int bufferOffset, final int length); static final int MAX_UNSIGNED_SHORT; }
@Test public void shouldPackFourUnsignedShortIntegersIntoLong() { final int int1 = 45454; final int int2 = 32234; final int int3 = 12231; final int int4 = 65000; final long longValue = ByteUtil.packLongWithUnsignedShortInts(int1, int2, int3, int4); final byte[] longBytes = new byte[8]; Bits.writeLong(longBytes, 0, longValue); assertEquals(int1, Bits.readShort(longBytes, 0) & 0xFFFF); assertEquals(int2, Bits.readShort(longBytes, 2) & 0xFFFF); assertEquals(int3, Bits.readShort(longBytes, 4) & 0xFFFF); assertEquals(int4, Bits.readShort(longBytes, 6) & 0xFFFF); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionForIntLargerThanMaxUnsignedShort() { final int int1 = (1 << 16); final int int2 = 32234; final int int3 = 12231; final int int4 = 65000; ByteUtil.packLongWithUnsignedShortInts(int1, int2, int3, int4); }