Exemplo n.º 1
0
    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());
      }
    }
Exemplo n.º 2
0
    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);
      }
    }