return it.hasNext();
}
@Override
public InputStream nextElement() {
ByteSource is;
try {
FileRange range = it.next();
is = getBlob(blobStore, range.getContentKey());
if (to != null || from != null) {
long start = 0;
if (from != null) {
start = Math.max(0, from - range.getStart());
// Enforced by the skipping logic
assert start <= is.size();
}
long end = is.size();
if (to != null) {
end = Math.min(to - range.getStart(), is.size());
// Enforced by the skipping logic
assert end >= 0;
}
long length = end - start;
if (length <= 0) {
assert length == 0;
// Easier than worrying about hasNext
is = EMPTY;
} else {
is = is.slice(start, length);
}
}
// TODO: Open buffered stream??
return is.openStream();
} catch (IOException e) {
throw new IllegalStateException("Error reading data", e);
}
}
});