Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent node.js Buffer in java?

I could not adapt some algorithm in js to java.

I have tried

ByteBuffer buffer = ByteBuffer.alocate(10);

buffer.put((byte)10000,0); 

it could not fix my problem. Also I tried byte array.

In javascript there is a code ;

...
var buf = new Buffer.alloc(10);
buf.writeUInt16LE(10000,0);
buf.write("test",5);
...

What is the equivalent buffer, buffer.write(), buffer.writeUInt16LE?

If there is not how can i figure out about this problem?

I would be very happy if someone can help me.

Thanks.

like image 621
Oguz Avatar asked Oct 25 '25 05:10

Oguz


1 Answers

I fixed my problem;

Firstly, in java I found that if we want to use little endian algorithm in bytebuffer there is a function that helps us for making encyription.

buffer.order(ByteOrder.LITTLE_ENDIAN);

after that I used putShort function for adding Unsigned 16 bit encyrpted data to the buffer, for Unsigned byte(UInt8) type in javascript I used put function and for Unsigned Integer(UInt32) type in javascript I used putInteger function.

Thanks.

like image 178
Oguz Avatar answered Oct 26 '25 21:10

Oguz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!