I am having ArrayIndexOutOfBoundsException error for my getBuffer method,
public class BufferPool {
private LPQueue<Buffer> queue;
private RandomAccessFile disk;
private int blockSize;
private int poolSize;
private Buffer[] pool;
public BufferPool(File file, int bufferNumber, int blockSize)
throws IOException {
this.blockSize = blockSize;
queue = new LPQueue<Buffer>(bufferNumber);
disk = new RandomAccessFile(file, "rw");
poolSize = ((int) disk.length() / blockSize);
pool = new Buffer[poolSize];
}
public Buffer getBuffer(int index) {
if (pool[index] == null) { // <<----------here!
pool[index] = newBuffer(index);
}
return pool[index];
}
}
Can you please help me to solve this problem out? This buffer pool is pool of the buffer to store the value of data to sort it later.. This get Buffer Gets a handle to a Buffer that represents the indexth block of the file that is backing this BufferPool. index is the index of the block we want to acquire. it returns a buffer handle to that block.