byte[] data = mByteCache.getIfPresent(bucketIndex);
if (data == null) {
data = getAndprefetchBuckets(bucketIndex);
}
final ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length);
int length = -1;
if (bucketOffset + bytes.length > SIZE_PER_BUCKET) {
length = SIZE_PER_BUCKET - bucketOffset;
} else {
length = bytes.length;
}
output.write(data, bucketOffset, length);
if (bucketOffset + bytes.length > SIZE_PER_BUCKET) {
data = mByteCache.getIfPresent(bucketIndex + 1);
if (data == null) {
data = getAndprefetchBuckets(bucketIndex + 1);
}
output.write(data, 0, bytes.length - (SIZE_PER_BUCKET - bucketOffset));
}
System.arraycopy(output.toByteArray(), 0, bytes, 0, bytes.length);
} catch (ExecutionException | InterruptedException exc) {
throw new IOException(exc);
}
}