diff --git a/google-cloud-storage/pom.xml b/google-cloud-storage/pom.xml
index 7fbba0aeeb..c6219b776d 100644
--- a/google-cloud-storage/pom.xml
+++ b/google-cloud-storage/pom.xml
@@ -96,6 +96,14 @@
com.google.protobuf
protobuf-java-util
+
+ io.grpc
+ grpc-core
+
+
+ io.grpc
+ grpc-protobuf
+
com.google.api.grpc
proto-google-common-protos
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java
index 704794a389..82789bcd2f 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java
@@ -48,19 +48,23 @@ public static GapicDownloadSessionBuilder create() {
* ultimately produced channel will not do any retries of its own.
*/
public ReadableByteChannelSessionBuilder byteChannel(
- ServerStreamingCallable read) {
- return new ReadableByteChannelSessionBuilder(read);
+ ServerStreamingCallable read,
+ ResponseContentLifecycleManager responseContentLifecycleManager) {
+ return new ReadableByteChannelSessionBuilder(read, responseContentLifecycleManager);
}
public static final class ReadableByteChannelSessionBuilder {
private final ServerStreamingCallable read;
+ private final ResponseContentLifecycleManager responseContentLifecycleManager;
private boolean autoGzipDecompression;
private Hasher hasher;
private ReadableByteChannelSessionBuilder(
- ServerStreamingCallable read) {
+ ServerStreamingCallable read,
+ ResponseContentLifecycleManager responseContentLifecycleManager) {
this.read = read;
+ this.responseContentLifecycleManager = responseContentLifecycleManager;
this.hasher = Hasher.noop();
this.autoGzipDecompression = false;
}
@@ -100,11 +104,13 @@ public UnbufferedReadableByteChannelSessionBuilder unbuffered() {
return (object, resultFuture) -> {
if (autoGzipDecompression) {
return new GzipReadableByteChannel(
- new GapicUnbufferedReadableByteChannel(resultFuture, read, object, hasher),
+ new GapicUnbufferedReadableByteChannel(
+ resultFuture, read, object, hasher, responseContentLifecycleManager),
ApiFutures.transform(
resultFuture, Object::getContentEncoding, MoreExecutors.directExecutor()));
} else {
- return new GapicUnbufferedReadableByteChannel(resultFuture, read, object, hasher);
+ return new GapicUnbufferedReadableByteChannel(
+ resultFuture, read, object, hasher, responseContentLifecycleManager);
}
};
}
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java
index 4b19c3f998..6cecc8dded 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java
@@ -16,8 +16,6 @@
package com.google.cloud.storage;
-import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.api.client.http.HttpStatusCodes;
import com.google.api.core.ApiFuture;
import com.google.api.core.SettableApiFuture;
@@ -25,6 +23,7 @@
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.cloud.storage.Crc32cValue.Crc32cLengthKnown;
import com.google.cloud.storage.UnbufferedReadableByteChannelSession.UnbufferedReadableByteChannel;
+import com.google.protobuf.ByteString;
import com.google.storage.v2.ChecksummedData;
import com.google.storage.v2.Object;
import com.google.storage.v2.ReadObjectRequest;
@@ -46,6 +45,7 @@ final class GapicUnbufferedReadableByteChannel
private final ReadObjectRequest req;
private final Hasher hasher;
private final LazyServerStreamIterator iter;
+ private final ResponseContentLifecycleManager rclm;
private boolean open = true;
private boolean complete = false;
@@ -53,18 +53,20 @@ final class GapicUnbufferedReadableByteChannel
private Object metadata;
- private ByteBuffer leftovers;
+ private ResponseContentLifecycleHandle leftovers;
GapicUnbufferedReadableByteChannel(
SettableApiFuture