ReadWrite { public static final void writeInt (int value, final ByteBuffer buffer, int start) { buffer.position(start); buffer.put((byte) (value >>> 24)); buffer.put((byte) (value >>> 16)); buffer.put((byte) (value >>> 8)); buffer.put((byte) value); } 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 testWriteInt () { ByteBuffer intBuffer = ByteBuffer.allocate(4); ReadWrite.writeInt(42, intBuffer, 0); Assert.assertTrue(ReadWrite.readUnsignedInt(intBuffer, 0) == 42); }