private int fetchBlock(long position, byte[] b, int off, int len) throws IOException { // read whole block into cache and then provide needed data long blockId = getBlock(position); int blockOffset = (int) getPosition(position); int lengthToReadInBlock = Math.min(len, _blockSize - blockOffset); if (checkCache(blockId, blockOffset, b, off, lengthToReadInBlock)) { return lengthToReadInBlock; } else { readIntoCacheAndResult(blockId, blockOffset, b, off, lengthToReadInBlock); } return lengthToReadInBlock; }
public IndexInput openInput(String name, int bufferSize) throws IOException { final IndexInput source = _directory.openInput(name, _blockSize); if (_blockCacheFileTypes == null || isCachableFile(name)) { return new CachedIndexInput(source, _blockSize, name, getFileCacheName(name), _cache, bufferSize); } return source; }
@Override protected void readInternal(byte[] b, int off, int len) throws IOException { long position = getFilePointer(); while (len > 0) { int length = fetchBlock(position, b, off, len); position += length; len -= length; off += length; } }