简体   繁体   中英

C sharp to Java : MemoryStream and BinaryReader

I am working on a network device and catching packets from it over network as UDP. In some parts i need to parse a byte array (packetBuffer) to get session header but i couldn't. I found a part of code but unfortunatelly it is C sharp and i also couldn't convert it to java. It is like below;

MemoryStream memstream = new MemoryStream(packetbuffer);
BinaryReader binreader = new BinaryReader(memstream);

byte[] sessionheader = binreader.ReadBytes(4);
ushort ROapdu_type = correctendianshortus(binreader.ReadUInt16());

I need to find what MemoryStream and BinaryReader in C# equivalent in Java is.

I appreciate for all your helps.

您可以使用getData获取 byte[],然后从结果数组中提取 4 个字节并使用ByteBuffer.wrap(result4Byte).getInt()将其转换为 int(您可能需要使用 order 将字节顺序设置为 little/big字节序)

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