When it comes to Java NIO MappedByteBuffer, is it possible to map part of different files into the buffer? Something like this:
buffer = infilechannel1.map(FileChannel.MapMode.READ_WRITE, infilechannel1.position(), infilechannel1.size());
Then something like this:
buffer = infilechannel2.map(FileChanne2.MapMode.READ_WRITE, infilechannel2.position(), infilechannel2.size());
Currently, what happens is that in the first "put", the limit of the buffer is already set to a certain value. The second "put" into the buffer causes a buffer overflow exception. I have allocated enough space to the buffer.
How would I update (i.e. append) this buffer with the values from the second file?
EDIT: My initial question was incorrect. Editing it so that it makes more sense.
I have some big files (say 4, and for now equal in size) and the files, even individually will not fit in memory. I have to perform operations on the 4 files and create a single output file. Since my memory is quite small compared to the size of the file, I can process only 4 blocks at a time, i.e., one block from each of the file at a time. I can either create multiple MemoryByteBuffers which maps to that particular block in files and then write into a ByteBuffer for processing OR I can directly write each block to the ByteBuffer.
Is there any advantage/ meaning in using MemoryByteBuffer in this scenario?