private BlockRead cacheBlock( String _lookup, BlockCache cache, BlockReader _currBlock, String block) throws IOException { if ((cache == null) || (_currBlock.getRawSize() > cache.getMaxSize())) { return new BlockRead(_currBlock, _currBlock.getRawSize()); } else { /** Try to fully read block for meta data if error try to close file */ byte b[] = null; try { b = new byte[(int) _currBlock.getRawSize()]; _currBlock.readFully(b); } catch (IOException e) { log.debug("Error full blockRead for file " + fileName + " for block " + block, e); throw e; } finally { _currBlock.close(); } CacheEntry ce = null; try { ce = cache.cacheBlock(_lookup, b); } catch (Exception e) { log.warn("Already cached block: " + _lookup, e); } if (ce == null) return new BlockRead(new DataInputStream(new ByteArrayInputStream(b)), b.length); else return new CachedBlockRead(ce, ce.getBuffer()); } }
public void cacheMetaBlock(String blockName, byte[] b) { if (_iCache == null) return; String _lookup = fileName + "M" + blockName; try { _iCache.cacheBlock(_lookup, b); } catch (Exception e) { log.warn("Already cached block: " + _lookup, e); } }
public BlockRead getCachedMetaBlock(String blockName) throws IOException { String _lookup = fileName + "M" + blockName; if (_iCache != null) { CacheEntry cacheEntry = _iCache.getBlock(_lookup); if (cacheEntry != null) { return new CachedBlockRead(cacheEntry, cacheEntry.getBuffer()); } } return null; }
private BlockRead getBlock(String _lookup, BlockCache cache, BlockLoader loader) throws IOException { BlockReader _currBlock; if (cache != null) { CacheEntry cb = null; cb = cache.getBlock(_lookup); if (cb != null) { return new CachedBlockRead(cb, cb.getBuffer()); } } /** grab the currBlock at this point the block is still in the data stream */ _currBlock = loader.get(); /** If the block is bigger than the cache just return the stream */ return cacheBlock(_lookup, cache, _currBlock, loader.getInfo()); }