22

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,304
  • 5
  • 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
  • 6,414
  • 4
  • 30
  • 48
Peter Lawrey
  • 513,304
  • 74
  • 731
  • 1,106
18

Guava now includes LittleEndianDataInputStream and LittleEndianDataOutputStream.

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

Luna
  • 1,367
  • 1
  • 16
  • 32