java 小端数据输入流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5862023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 13:09:58  来源:igfitidea点击:

little endian DataInputStream

java

提问by Saideira

Is there any way to force DataInputStream to read little-endian data?? Thx

有没有办法强制 DataInputStream 读取小端数据?谢谢

PS. Doing byte-buffer conversions is not very convinient as I'm dealing with C-type structs that have lots of 32-bit and 16-bit members.

附注。进行字节缓冲区转换不是很方便,因为我正在处理具有大量 32 位和 16 位成员的 C 类型结构。

采纳答案by Steven Fines

No. You'd need to wrap the stream to convert from big endian to little endian. You can google and find several implementations of little endian streams....

不。您需要包装流以从大端转换为小端。您可以谷歌并找到小端流的几种实现....

回答by Peter Lawrey

Perhaps you can use ByteBufferwhich allows order(ByteOrder.LITTLE_ENDIAN)After that most of the methods are like DataInputStream.

也许你可以使用ByteBufferwhich allowedorder(ByteOrder.LITTLE_ENDIAN)之后,大多数方法都像DataInputStream.

回答by Luna

Guavanow includes LittleEndianDataInputStreamand LittleEndianDataOutputStream.

Guava现在包括LittleEndianDataInputStreamLittleEndianDataOutputStream

If you aren't already using Guava Peter Lawrey's answer above is probably better.

如果您还没有使用 Guava Peter Lawrey 上面的答案可能会更好。