> If you have written the integer in Java ( using DataOutputStream), Unix or
> any other Big endian system
...
> If you have written the int on a windows or any other small endian system
> (Java is big-endian on all platforms) use something like
Just a clarification.
The Java language does not expose the byte ordering of the underlying
hardware in this manner, there is no aliasing of byte and integer
pointers where you might detect the difference.
When you are reading or writing an input or output stream and you
translate a series of bytes to an integer or vice versa, then you
need to do that consistently - LSB first or MSB first - your choice.
Most file formats state the byte order of the data and you must compose
it as per that specification when you read in data from that format.
The DataInput and DataOutput interfaces that the corresponding stream
classes implement specify the byte order that they write bytes in for
their various read<Type> and write<Type> methods. If that byte ordering
matches the ordering specified by the file format you are trying to
read (or if the file itself was generated by the corresponding output
stream class) then these classes will automatically do the appropriate
byte ordering for you.
...jim