23

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

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.

Saideira
  • 2,374
  • 6
  • 38
  • 49

2 Answers2

28

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

Denis Zavedeev
  • 7,627
  • 4
  • 32
  • 53
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
19

Guava now includes LittleEndianDataInputStream and LittleEndianDataOutputStream.

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

Luna
  • 1,447
  • 1
  • 18
  • 32