Posted by byhisdeeds
on December 17, 2007 at 5:35 AM PST
I have an application that maintains a file consisting of a fixed size header and variable size data section with a FileChannel and MappedByteBuffer. To read and write to the header I maintain a header byte buffer via:
FileChannel ioc = new RandomAccessFile(file, "rw").getChannel();
MappedByteBuffer ioh = ioc.map(FileChannel.MapMode.READ_WRITE, 0, HEADER_SIZE);
The header holds a mximum of 8192 entries, each of which consists of the offset and length a data chunk, which can be up to 64K in size. To read and write the header I use:
ioh.getLong(position) and ioh.putLong(position, new_value).
To access the data I use the file channel's read and write:
numBytes = ioc.write(dataBuffer);
I wish to have the best possible access performance for both the header (which indicates if a particular chunk is available), and the data. Can anyone say whether my choice of methods for reading and writing is the best.