ByteWrite { public static int set(byte value, byte[] dst, int startIndex) { return setByte(value, dst, startIndex); } private  ByteWrite(); static int set(byte value, byte[] dst, int startIndex); static int set(boolean value, byte[] dst, int startIndex); static int set(short value, byte[] dst, int startIndex); static int set(int value, byte[] dst, int startIndex); static int set(long value, byte[] dst, int startIndex); static int set(byte[] src, int srcStartIndex, int length, byte[] dst, int dstStartIndex); static int setByte(byte value, byte[] dst, int startIndex); static int setBoolean(boolean value, byte[] dst, int startIndex); static int setShort(short value, byte[] dst, int startIndex); static int setInt(int value, byte[] dst, int startIndex); static int setLong(long value, byte[] dst, int startIndex); static int setBytes(byte[] src, int srcStartIndex, int length, byte[] dst, int dstStartIndex);  }
@Test public void testInt() { final int TEST_CASE = 164214632; ByteBuffer buffer = ByteBuffer.allocate(4); buffer = buffer.order(ByteOrder.BIG_ENDIAN); buffer.putInt(TEST_CASE); byte[] writeData = new byte[4]; ByteWrite.set(TEST_CASE, writeData, 0); Assert.assertArrayEquals(buffer.array(), writeData); }
@Test public void testLong() { final long TEST_CASE = 1642146535132L; ByteBuffer buffer = ByteBuffer.allocate(8); buffer = buffer.order(ByteOrder.BIG_ENDIAN); buffer.putLong(TEST_CASE); byte[] writeData = new byte[8]; ByteWrite.set(TEST_CASE, writeData, 0); Assert.assertArrayEquals(buffer.array(), writeData); }
@Test public void testByte() { final byte TEST_CASE = 111; ByteBuffer buffer = ByteBuffer.allocate(1); buffer = buffer.order(ByteOrder.BIG_ENDIAN); buffer.put(TEST_CASE); byte[] writeData = new byte[1]; ByteWrite.set(TEST_CASE, writeData, 0); Assert.assertArrayEquals(buffer.array(), writeData); }
@Test public void testShort() { final short TEST_CASE = (short) 62510; ByteBuffer buffer = ByteBuffer.allocate(2); buffer = buffer.order(ByteOrder.BIG_ENDIAN); buffer.putShort(TEST_CASE); byte[] writeData = new byte[2]; ByteWrite.set(TEST_CASE, writeData, 0); Assert.assertArrayEquals(buffer.array(), writeData); }