简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM