}
if (i == (bestEnd - 1)) {
c.setEnd(range.getEnd());
}
final BlobData blob = blobStore.find(range.getContentKey());
if (blob == null) {
throw new IOException("Unable to open storage for range: " + range);
}
blob.copyTo(fos);
}
}
if (!c.hasStart() || !c.hasEnd()) {
throw new IllegalStateException();
}
ByteString hash = ByteString.copyFrom(md5.hash().asBytes());
BlobData blobData = new BlobData(tempFile.getFile(), hash);
blobStore.put(blobData);
if (PARANOID) {
BlobData blob = blobStore.find(blobData.getHash());
if (blob == null) {
throw new IllegalStateException();
}
ByteString checkHash = ByteString.copyFrom(blob.hash(Hashing.md5()).asBytes());
if (!blobData.getHash().equals(checkHash)) {
log.warn("Hash mismatch: {} vs {}", blobData.getHash(), checkHash);
throw new IllegalStateException();
}
}