public Reader(CachableBlockFile.Reader cache, FSDataInputStream fin, long fileLength, Configuration conf) throws IOException {
this.in = fin;
this.conf = conf;
BlockRead cachedMetaIndex = cache.getCachedMetaBlock(META_NAME);
BlockRead cachedDataIndex = cache.getCachedMetaBlock(DataIndex.BLOCK_NAME);
if (cachedMetaIndex == null || cachedDataIndex == null) {
// move the cursor to the beginning of the tail, containing: offset to the
// meta block index, version and magic
fin.seek(fileLength - Magic.size() - Version.size() - Long.SIZE / Byte.SIZE);
long offsetIndexMeta = fin.readLong();
version = new Version(fin);
Magic.readAndVerify(fin);
if (!version.compatibleWith(BCFile.API_VERSION)) {
throw new RuntimeException("Incompatible BCFile fileBCFileVersion.");
}
// read meta index
fin.seek(offsetIndexMeta);
metaIndex = new MetaIndex(fin);
if (cachedMetaIndex == null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
metaIndex.write(dos);
dos.close();
cache.cacheMetaBlock(META_NAME, baos.toByteArray());
}
// read data:BCFile.index, the data block index
if (cachedDataIndex == null) {
BlockReader blockR = getMetaBlock(DataIndex.BLOCK_NAME);
cachedDataIndex = cache.cacheMetaBlock(DataIndex.BLOCK_NAME, blockR);
}
dataIndex = new DataIndex(cachedDataIndex);
cachedDataIndex.close();
} else {
// Logger.getLogger(Reader.class).debug("Read bcfile !METADATA from cache");
version = null;
metaIndex = new MetaIndex(cachedMetaIndex);