I am trying to send a Long value that represents a filesize into a 128 byte data packet, the first byte is a header then I have reserved the next 8 bytes for the filesize.
I have done some research and found a class called BigInteger
that does this.
My problem is knowing how many of the bytes to read back off at the other side, as If I read all 8 on a long value that doesnt fill all 8 then I get a wrong value, here is my code.
//Create Byte array and append to packet
BigInteger big = new BigInteger(Long.toString(f
byte testlong = new byte;
testlong = big.toByteArray();
String dickString = new String(testlong);
gValue() );//test to see if its seding the right value
//Copy to the packet
0, testbuffer, 1, 8);
// I get an arrayindex Out Of Bounds error here
//Read from packet
byte fileSize = new byte;
//read back the 8 bytes from the data packet
r, 1, fileSize, 0, 8);
BigInteger big2 = new BigInteger(fileSize);
I can get it working with a small number eg 352, but I have to use 2 bytes instead of 8 to avoid the outofbounds exception.
Appreciate any help