简体   繁体   English

Java中等效的node.js缓冲区是什么?

[英]What is the equivalent node.js Buffer in java?

I could not adapt some algorithm in js to java. 我无法将js中的某些算法适应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 ; 在javascript中有一个代码;

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

What is the equivalent buffer, buffer.write(), buffer.writeUInt16LE? 什么是等效缓冲区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. 首先,在Java中,我发现如果我们想在字节缓冲区中使用Little Endian算法,则有一个函数可以帮助我们进行密级化。

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. 之后,我使用putShort函数将无符号的16位加密数据添加到缓冲区中,对于javascript中的Unsigned byte(UInt8)类型,我使用了put函数;对于javascript中的Unsigned Integer(UInt32)类型,我使用了putInteger函数。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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