/** * 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; }
/** * Returns a new builder for an immutable range map. */ public static <K extends Comparable<?>, V> Builder<K, V> builder() { return new Builder<K, V>(); }
/** * Copies all associations from the specified range map into this builder. */ @CanIgnoreReturnValue public Builder<K, V> putAll(RangeMap<K, ? extends V> rangeMap) { for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) { put(entry.getKey(), entry.getValue()); } return this; }