/** * Builds a mapping of block locations to file byte range */ private ImmutableRangeMap<Long,BlockLocation> buildBlockMap(FileStatus status) throws IOException { final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time(); BlockLocation[] blocks; ImmutableRangeMap<Long,BlockLocation> blockMap; blocks = fs.getFileBlockLocations(status, 0, status.getLen()); ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>(); for (BlockLocation block : blocks) { long start = block.getOffset(); long end = start + block.getLength(); Range<Long> range = Range.closedOpen(start, end); blockMapBuilder = blockMapBuilder.put(range, block); } blockMap = blockMapBuilder.build(); blockMapMap.put(status.getPath(), blockMap); context.stop(); return blockMap; }
Object createRangeMap() { Builder<K, V> builder = new Builder<K, V>(); for (Entry<Range<K>, V> entry : mapOfRanges.entrySet()) { builder.put(entry.getKey(), entry.getValue()); } return builder.build(); }
/** * Returns a new builder for an immutable range map. */ public static <K extends Comparable<?>, V> Builder<K, V> builder() { return new Builder<K, V>(); }