Zom-B wrote:Wrap it in a java.nio.ByteBuffer and use its various getZZZ methods. I think this is as fast as you can get in Java.
Rewriting it so it wraps the byte's in a DataInputStream and use readInt, readLong, etc also makes the running efficiency drop a lot compared to c-type casting, which is instant.
To make matters worse, C types are in Intel byte format while Java types are in Motorola byte format.You added this after my reply. Note that ByteBuffer takes care of this with the order(ByteOrder) method.
using handle.readInt() gives wrong results and I have to do
handle.read() | (handle.read() | (handle.read() | handle.read() << 8) << 8) << 8;
so I baically have to rewrite the DataInputStream class from scratch.
To make matters worse, C types are in Intel byte format while Java types are in Motorola byte format.C types on AMD/Intel are in little endian/Intel order. C type on Sparc/RISC system are in big-endian i.e. whatever the native architecture does. BTW, the x64 64-bit extension is a design owned my AMD and licensed to Intel. Intel have designed RISC processors which natively support big endian.