Edited by: HrPeanut on Aug 13, 2008 6:54 AM
Scan 1 Byte, Test if it's FF If so, Then Test the Previous Byte for EE or DD. If test is True, then Skip 99 Bytes, save Location, and Continue. (99 Bytes for Data to Follow these EEFF or DDFF Headers). Else, Skip to the Next Byte and Continue.
DrLaszloJamf wrote:yea I did some reading, and no, RandomAccessFile does NOT buffer. I'll try out bufferedInputstream.
MappedByteBuffer ? Or use BufferedInputStream. I think you may be incurring many low level read operations if you use RandomAccessFile like that -- it doesn't buffer, does it?
The bulk reads use the get(byte) and get(long) instead of individual get() or read() or readLong() calls as the stream and random access file versions do.
Stream byte-at-a-time mean 5980.4 ms DataStream word-at-a-time mean 816.0 ms Random-access byte-at-a-time mean 5225.8 ms Random-access word-at-a-time mean 6806.6 ms Buffer byte-at-a-time mean 65.8 ms Buffer word-at-a-time mean 37.8 ms Buffer bulk read byte-at-a-time mean 45.4 ms Buffer bulk read word-at-a-time mean 34.1 ms Random-access bulk byte-scan mean 38.9 ms Stream bulk byte-scan mean 38.5 ms
But that will only matter if you have ridiculously fast IO or (as in the timings above) the file's already in the OS's cache.
long v = in.readLong() ^ 0xffffffffffffffffL; if (((v - 0x0101010101010101L) & ~v & 0x8080808080808080L) != 0) for (int i = 0; i < 64; i += 8) if ( ((v >> i) & 0xffL) == 0 ) ++count;