Perhaps there is a ready-made solution, but I would probably just wrap an array of bytes in a simple class.
public class ByteArrayWrapper { private byte [] bytes; private long readCount = 0; public ByteArrayWrapper( byte [] bytes ) { this.bytes = bytes; } public int getSize() { return bytes.length; } public byte getByte( int index ) { readCount++; return bytes[ index ]; } public long getReadCount() { return readCount; } }
Something like that. Of course, this affects the working time, but not very much. You can try and once the difference, if you find that it is important, we will have to find another way.
source share