}
final long end = Math.min(file.getLen(), start + len);
if (hints.length <= 1 || end <= start) {
// Return an emtpy host list, as hadoop expects at least one location.
final BlockLocation[] result = new BlockLocation[1];
result[0] = new BlockLocation(
null, null, start, Math.max(0L, end - start));
return result;
}
final int blkcnt =
(int)((end - 1) / blockSize - start / blockSize + 1);
final BlockLocation[] result = new BlockLocation[blkcnt];
final ArrayList<String> hlist = new ArrayList<String>();
long pos = start - start % blockSize;
for(int i = 0, m = 1; i < blkcnt; ++i) {
hlist.clear();
if (m < hints.length) {
final String[] locs = hints[m++];
hlist.ensureCapacity(locs.length);
for(int k = 0; k < locs.length; ++k) {
final int idx = locs[k].lastIndexOf(':');
final String host = 0 < idx ? locs[k].substring(0, idx) : locs[k];
if (! hlist.contains(host)) {
hlist.add(host);
}
}
}
final long lpos = pos < start ? start : pos;
final long bend = pos + blockSize;
final int hsz = hlist.size();
result[i] = new BlockLocation(
null,
hsz <= 0 ? null : hlist.toArray(new String[hsz]),
lpos,
(bend < end ? bend : end) - lpos
);