Re-optimize LocalBlobStore.getBlob with ranges

This fixes a memory regression from
8de7b696e1 where the transient BlobStore
changed from a ByteSource to a byte[].
This commit is contained in:
Andrew Gaul 2021-06-24 20:57:30 +09:00 committed by Andrew Gaul
parent 2791f47046
commit d1bd51f7f1
1 changed files with 7 additions and 4 deletions

View File

@ -682,10 +682,13 @@ public final class LocalBlobStore implements BlobStore {
// Try to convert payload to ByteSource, otherwise wrap it.
ByteSource byteSource;
try {
byteSource = (ByteSource) blob.getPayload().getRawContent();
} catch (ClassCastException cce) {
// This should not happen; both FilesystemStorageStrategyImpl and TransientStorageStrategy return ByteSource
Object object = blob.getPayload().getRawContent();
if (object instanceof ByteSource) {
byteSource = (ByteSource) object;
} else if (object instanceof byte[]) {
byteSource = ByteSource.wrap((byte[]) object);
} else {
// This should not happen.
try {
byteSource = ByteSource.wrap(ByteStreams2.toByteArrayAndClose(blob.getPayload().openStream()));
} catch (IOException e) {