ReadWrite { public static final int readThreeByteInt (ByteBuffer buffer, int start) { final byte b1 = buffer.get(start); final byte b2 = buffer.get(start + 1); final byte b3 = buffer.get(start + 2); return ((b1 & 255) << 16) | ((b2 & 255) << 8) | (b3 & 255); } private  ReadWrite(); static final int readOneByteInt(ByteBuffer buffer, int start); static final int readOneByteInt(byte[] array, int start); static final int readTwoByteInt(ByteBuffer buffer, int start); static final int readTwoByteInt(byte[] array, int start); static final int readThreeByteInt(ByteBuffer buffer, int start); static final int readThreeByteInt(byte[] array, int start); static final int readFourByteInt(ByteBuffer buffer, int start); static final int readFourByteInt(byte[] array, int start); static ByteBuffer[] stringToTextDataSegments(String string, int bufferSize); static final void appendTextDataSegmentToStringBuffer(final ByteBuffer byteBuffer, final StringBuilder stringBuilder); static final void writeInt(int value, final ByteBuffer buffer, int start); static String byteBufferToString(final ByteBuffer buffer); static byte[] longToBytes(final long value); static void writeLong(final ByteBuffer buffer, final long value, final int index); static void writeTwoByteInt(final ByteBuffer buffer, final int value, final int index); static void writeThreeByteInt(final ByteBuffer buffer, final int value, final int index); static long readUnsignedInt(final ByteBuffer buffer, final int start);  }
@Test public void testReadThreeByteIntByteArrayInt () { byte[] bytes = new byte[3]; for (int i = 0; i < 16777216; i++) { int threeByte = ReadWrite.readThreeByteInt(bytes, 0); if (i != threeByte) { System.out.println(i + " " + java.util.Arrays.toString(bytes) + ReadWrite.readThreeByteInt(bytes, 0)); Assert.fail("wrong number read"); } else increment(bytes); } }