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.
RandomAccessFile
and provides methods
that mimick the behaviour of its methods but are not final
public
it can be reused.
EncapsulatedRandomAccessFile
and bolts the
ByteSwapper
so that bytes can be transparently swapped.
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