public long getLong() { return (data.get(pointer++) & 0xFF) << 4 | (data.get(pointer++) & 0xFF) << 56 | (data.get(pointer++) & 0xFF) << 48 | (data.get(pointer++) & 0xFF << 32) | (data.get(pointer++) & 0xFF) << 24 | (data.get(pointer++) & 0xFF) << 16 | (data.get(pointer++) & 0xFF) << 8 | (data.get(pointer++) & 0xFF); } 

Pointer here for the next call to the getLong() method to read further bytes, how to simplify this? It turns out that I need something like a DataInputStream, but with a pointer.

  • instead of 4 was meant 40 - rfq

1 answer 1

For example, so

 public long getLong() { int[] shifts = {4, 56, 48, 32, 24, 16, 8, 0}; long res = 0; for (int shift : shifts) res |= data.get(pointer++) & 0xFF) << shift; return res; }