-1

I am getting the output

[B@3a2fc571

byte[] rate = new byte[8];
ByteBuffer.wrap(rate).putDouble(Flow_Rate);

I used the function to write this data of_vendor.setData(rate); But the capacity is same and it is not writing that byte after using the function when the function accept array of byte[]. after converting it to ByteBuffer the output is same and the output is

java.nio.HeapByteBuffer[pos=0 lim=0 cap=8]
Xobiiii
  • 21
  • 7
  • 2
    You seem to be printing the array itself instead of its contents. Try `Arrays.toString(rate);` – awksp Jun 12 '14 at 01:20
  • 1
    What do you expect the output to be and why? – Sotirios Delimanolis Jun 12 '14 at 01:23
  • I want to write that byte buffer using the function i created an object of the class and using the function of that class to write some data on it. but the array is created but when i am using the function it is giving the contents of an array rather the data is not written on to it. Why? – Xobiiii Jun 12 '14 at 01:29

1 Answers1

-1

wrap is an static method of ByteBuffer and returns a new instance of ByteBuffer, you must capture the instance and then manipulate it, try something like this:

byte[] rate = new byte[8];
ByteBuffer obj = ByteBuffer.wrap(rate)
obj.putDouble(Flow_Rate);
...
return obj
  • I already used this technique still the size is zero and the capacity is not changing it is same. means it i created array of 8 it is same. – Xobiiii Jun 12 '14 at 01:47
  • in my code i'm using this method `ByteBuffer bb = ByteBuffer.allocate(msgLength); bb.put(REPLY_BEGIN); bb.put(ByteBuffer.allocate(2).putShort(msgLength).array()); bb.put(Hex.decodeHex(msg.getTid().toCharArray()), 0, 7); bb.put(Hex.decodeHex(msg.getCmd().toCharArray()), 0, 2); bb.put(message.getBody()); bb.put(ByteBuffer.allocate(2).putShort(checksum(bb.array(), msgLength - 4)).array()); bb.put(ENDLINE); ` – Emilio Navarrete Lineros Jun 12 '14 at 02:05