File IO

The RandomAccessFile class provided with java assumes that bytes being read are in the correct order. In reality your java application may have to read files with different byte ordering expected by java.

The file IO methods in RandomAccessFile are declared as final. i.e. it is not possible to add byteswapping code to a subclass of RandomAccessFile.

The cornerstone of object orientation is encapsulation used to hide the implementation details of the class. I also permits objects to mimick the behaviour of another class by encapsulation and provision of a similar intrface... a sort of inheritance by the back door.

The classes above provide a mechanism for byteswapping, but are unable to tell whether bytes are in the wrong order in the first place. Looking at the first few bytes in a file is normally sufficient to determine the order of the bytes, Once your application has done this, if the byte ordering is wrong, it must set byteSwapping to be true.

Hexadecimal codes aid the diagnosis of oddly ordered bytes. The class libararies do not have any hexadecimal conversion functions, so here's one I prepared earlier Hex.java