I use long
as a 64-bit value. If it is timestamp you might not need to worry about overflows, but if you are there are way to correct for this. A 32-bit int
value is just int
in Java.
System.arraycopy just copies bytes, it has no idea about endianness and doesn't change it.
Most likely you want to use ByteBuffer with native byte order. and you will get what you want.
DatagramSocket ds = ...
ByteBuffer bb = ByteBuffer.wrap(ds.getData()).order(ByteOrder.nativeOrder());
long timestamp = bb.getLong();
int number = bb.getInt();
// use the bb to read the encoded data.