So what I\'m trying to do here is get a float[]
, convert it to byte[]
, send it through the network as a datagram packet and then convert it back to
ByteBuffer document: https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html
final static int nbBytesInFloat = Float.SIZE / Byte.SIZE;
public static byte[] toByteArray(float[] floatArray){
byte[] result = new byte[floatArray.length * nbBytesInFloat];
ByteBuffer wrappedBytes = ByteBuffer.wrap(result);
for(int i=0;i