GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(gax): replace InputStream with InputStreamSupplier in resumable upload public surfaces by whowes · Pull Request #14521 · googleapis/google-cloud-java

feat(gax): replace InputStream with InputStreamSupplier in resumable upload public surfaces #14521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
whowes merged 1 commit into main from whowes/resumable-upload-supplier
Sep 29, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(gax): replace InputStream with InputStreamSupplier in resumable upload public surfaces #14521

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
6168784
feat(gax): accept InputStreamSupplier for resumable upload payloads
whowes Sep 25, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

11 changes: 7 additions & 4 deletions 11 ...apic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceClient.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.api.gax.paging.AbstractPage;
import com.google.api.gax.paging.AbstractPagedListResponse;
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.InputStreamSupplier;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.ResumableUploadCallable;
import com.google.api.gax.rpc.ResumableUploadOptions;
Expand All @@ -41,7 +42,6 @@
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStub;
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStubSettings;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
Expand Down Expand Up @@ -85,7 +85,7 @@
* <td>
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
* <ul>
* <li><p> uploadMedia(UploadMediaRequest request, InputStream payload, ResumableUploadOptions options)
* <li><p> uploadMedia(UploadMediaRequest request, InputStreamSupplier payload, ResumableUploadOptions options)
* </ul>
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
* <ul>
Expand Down Expand Up @@ -282,12 +282,15 @@ public ResumableUploadServiceStub getStub() {
* A method with media_upload annotation enabled.
*
* @param request The request object containing all of the parameters for the API call.
* @param payload The payload data stream to upload.
* @param payload Supplies the payload data stream to upload. The stream is closed automatically
* when the upload succeeds, fails, times out, or is cancelled.
* @param options The options to apply to this upload, or null to use defaults.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final UploadMediaResponse uploadMedia(
UploadMediaRequest request, InputStream payload, @Nullable ResumableUploadOptions options) {
UploadMediaRequest request,
InputStreamSupplier payload,
@Nullable ResumableUploadOptions options) {
return ApiExceptions.callAndTranslateApiException(
uploadMediaCallable().futureCall(request, payload, options));
}
Expand Down
251 changes: 118 additions & 133 deletions 251 ...owcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITResumableUpload.java
Show comments
View file
Open in desktop

Large diffs are not rendered by default.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

4 changes: 3 additions & 1 deletion 4 ...in/java/com/google/api/generator/gapic/composer/comment/ServiceClientCommentComposer.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public class ServiceClientCommentComposer {
private static final String REQUEST_PARAM_DESCRIPTION =
"The request object containing all of the parameters for the API call.";
private static final String PAYLOAD_PARAM_NAME = "payload";
private static final String PAYLOAD_PARAM_DESCRIPTION = "The payload data stream to upload.";
private static final String PAYLOAD_PARAM_DESCRIPTION =
"Supplies the payload data stream to upload. The stream is closed automatically when the"
+ " upload succeeds, fails, times out, or is cancelled.";
private static final String OPTIONS_PARAM_NAME = "options";
private static final String OPTIONS_PARAM_DESCRIPTION =
"The options to apply to this upload, or null to use defaults.";
Expand Down
9 changes: 6 additions & 3 deletions 9 ...va/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.BidiStreamingCallable;
import com.google.api.gax.rpc.ClientStreamingCallable;
import com.google.api.gax.rpc.InputStreamSupplier;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.ResumableUploadCallable;
Expand Down Expand Up @@ -91,7 +92,6 @@
import com.google.longrunning.Operation;
import com.google.rpc.Status;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -959,7 +959,10 @@ private static MethodDefinition createResumableUploadDefaultMethod(
VariableExpr payloadArgVarExpr =
VariableExpr.builder()
.setVariable(
Variable.builder().setName("payload").setType(typeStore.get("InputStream")).build())
Variable.builder()
.setName("payload")
.setType(typeStore.get("InputStreamSupplier"))
.build())
.setIsDecl(true)
.build();
VariableExpr optionsArgVarExpr =
Expand Down Expand Up @@ -1905,7 +1908,7 @@ private static TypeStore createTypes(Service service, Map<String, Message> messa
BidiStreamingCallable.class,
ClientStreamingCallable.class,
Generated.class,
InputStream.class,
InputStreamSupplier.class,
InterruptedException.class,
IOException.class,
MoreExecutors.class,
Expand Down
11 changes: 7 additions & 4 deletions 11 .../test/java/com/google/api/generator/gapic/composer/grpc/goldens/MediaServiceClient.golden
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package com.google.showcase.v1beta1;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.InputStreamSupplier;
import com.google.api.gax.rpc.ResumableUploadCallable;
import com.google.api.gax.rpc.ResumableUploadOptions;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.showcase.v1beta1.stub.MediaServiceStub;
import com.google.showcase.v1beta1.stub.MediaServiceStubSettings;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
import org.jspecify.annotations.NullMarked;
Expand Down Expand Up @@ -49,7 +49,7 @@ import org.jspecify.annotations.Nullable;
* <td>
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
* <ul>
* <li><p> uploadMedia(UploadMediaRequest request, InputStream payload, ResumableUploadOptions options)
* <li><p> uploadMedia(UploadMediaRequest request, InputStreamSupplier payload, ResumableUploadOptions options)
* </ul>
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
* <ul>
Expand Down Expand Up @@ -166,12 +166,15 @@ public class MediaServiceClient implements BackgroundResource {
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* @param request The request object containing all of the parameters for the API call.
* @param payload The payload data stream to upload.
* @param payload Supplies the payload data stream to upload. The stream is closed automatically
* when the upload succeeds, fails, times out, or is cancelled.
* @param options The options to apply to this upload, or null to use defaults.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final UploadMediaResponse uploadMedia(
UploadMediaRequest request, InputStream payload, @Nullable ResumableUploadOptions options) {
UploadMediaRequest request,
InputStreamSupplier payload,
@Nullable ResumableUploadOptions options) {
return ApiExceptions.callAndTranslateApiException(
uploadMediaCallable().futureCall(request, payload, options));
}
Expand Down
56 changes: 56 additions & 0 deletions 56 sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/InputStreamSupplier.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2026 Google LLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.api.gax.rpc;

import com.google.api.core.BetaApi;
import java.io.IOException;
import java.io.InputStream;
import org.jspecify.annotations.NullMarked;

/**
* A functional interface that supplies an {@link InputStream} and may throw {@link IOException}.
*/
@BetaApi
@NullMarked
@FunctionalInterface
public interface InputStreamSupplier {

/**
* Opens or returns the {@link InputStream} to be read.
Comment thread

@blakeli0 blakeli0 Sep 28, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Add a comment mentioning that the stream will be managed/closed when the resumable upload is completed/failed/cancelled.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@whowes whowes Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
*
* <p>The returned stream is managed by the resumable upload and is closed automatically when the
* upload succeeds, fails, times out, or is cancelled. Callers should not close the stream
* themselves.
*
* @return a non-null input stream over the payload data
* @throws IOException if an I/O error occurs when opening or obtaining the stream
*/
InputStream get() throws IOException;
}
19 changes: 9 additions & 10 deletions 19 ...tform-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/ResumableUploadCallable.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
package com.google.api.gax.rpc;

import com.google.api.core.BetaApi;
import java.io.InputStream;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

Expand All @@ -50,51 +49,51 @@ protected ResumableUploadCallable() {}
/**
* Performs a new resumable upload asynchronously with options overrides and default call context.
*
* <p>The provided {@code payload} stream is consumed asynchronously by the returned {@link
* <p>Streams from the provided {@code payload} are consumed asynchronously by the returned {@link
* ResumableUploadFuture} and will be closed automatically upon completion, failure, or
* cancellation.
*
* @param request the request message
* @param payload the data payload input stream to upload and close
* @param payload supplier of the data payload input stream to upload and close
* @param options request-level upload options overrides; may be {@code null}
* @return future for tracking and controlling the upload
*/
public ResumableUploadFuture<ResponseT> futureCall(
RequestT request, InputStream payload, @Nullable ResumableUploadOptions options) {
RequestT request, InputStreamSupplier payload, @Nullable ResumableUploadOptions options) {
return futureCall(request, payload, null, options);
}

/**
* Performs a new resumable upload asynchronously with call context and options overrides.
*
* <p>The provided {@code payload} stream is consumed asynchronously by the returned {@link
* <p>Streams from the provided {@code payload} are consumed asynchronously by the returned {@link
* ResumableUploadFuture} and will be closed automatically upon completion, failure, or
* cancellation.
*
* @param request the request message
* @param payload the data payload input stream to upload and close
* @param payload supplier of the data payload input stream to upload and close
* @param context call context overrides; may be {@code null}
* @param options request-level upload options overrides; may be {@code null}
* @return future for tracking and controlling the upload
*/
public abstract ResumableUploadFuture<ResponseT> futureCall(
RequestT request,
InputStream payload,
InputStreamSupplier payload,
@Nullable ApiCallContext context,
@Nullable ResumableUploadOptions options);

/**
* Resumes an existing resumable upload session asynchronously using a saved session URL.
*
* <p>The provided {@code payload} stream is consumed asynchronously by the returned {@link
* <p>Streams from the provided {@code payload} are consumed asynchronously by the returned {@link
* ResumableUploadFuture} and will be closed automatically upon completion, failure, or
* cancellation.
*
* @param sessionUrl the upload session URL
* @param payload the data payload input stream to upload and close
* @param payload supplier of the data payload input stream to upload and close
* @param options upload options overrides; may be {@code null}
* @return future for tracking and controlling the upload
*/
public abstract ResumableUploadFuture<ResponseT> resumeCall(
String sessionUrl, InputStream payload, @Nullable ResumableUploadOptions options);
String sessionUrl, InputStreamSupplier payload, @Nullable ResumableUploadOptions options);
}
5 changes: 2 additions & 3 deletions 5 ...m-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/ResumableUploadCallableImpl.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.google.api.gax.retrying.RetryAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.retrying.ScheduledRetryingExecutor;
import java.io.InputStream;
import java.time.Duration;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -104,7 +103,7 @@ public ResumableUploadCallableImpl(
@Override
public ResumableUploadFuture<ResponseT> futureCall(
RequestT request,
InputStream payload,
InputStreamSupplier payload,
@Nullable ApiCallContext context,
@Nullable ResumableUploadOptions options) {
checkNotNull(request, "request must not be null");
Expand All @@ -131,7 +130,7 @@ public ResumableUploadFuture<ResponseT> futureCall(

@Override
public ResumableUploadFuture<ResponseT> resumeCall(
String sessionUrl, InputStream payload, @Nullable ResumableUploadOptions options) {
String sessionUrl, InputStreamSupplier payload, @Nullable ResumableUploadOptions options) {
throw new UnsupportedOperationException("Session resumption is not yet implemented.");
}

Expand Down
20 changes: 11 additions & 9 deletions 20 ...orm-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/ResumableUploadFutureImpl.java
Show comments Show annotations
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
uploadChunkCallable;
private final UnaryCallable<QueryStatusRequest, QueryStatusResponse<ResponseT>>
queryStatusCallable;
private final InputStream payload;
private final ResumableUploadOptions options;
private final ApiCallContext callContext;
private final ScheduledExecutorService executor;
Expand All @@ -85,6 +84,7 @@
new ResumableUploadProgressTracker();
private final SettableApiFuture<ResponseT> resultFuture = SettableApiFuture.create();

private volatile @Nullable InputStream payload;

Check warning on line 87 in sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/ResumableUploadFutureImpl.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Use a thread-safe type; adding "volatile" is not enough to make this field thread-safe.

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AaDbxd5yC7il__P96RcW&open=AaDbxd5yC7il__P96RcW&pullRequest=14521
private volatile @Nullable String uploadSessionUrl;

// Tracks the current operation's Future (start, chunk upload) to propagate cancellation, or
Expand All @@ -96,28 +96,28 @@
* Creates and initiates a new resumable upload future tracking session initiation and chunk
* streaming.
*
* <p>The provided {@code payload} stream is managed by the returned future and will be closed
* automatically upon completion, failure, or cancellation.
* <p>The stream opened from {@code payloadSupplier} is managed by the returned future and will be
* closed automatically upon completion, failure, or cancellation.
*/
static <ResponseT> ResumableUploadFutureImpl<ResponseT> create(
ApiFuture<ResumableUploadSession> startFuture,
UnaryCallable<ChunkUploadRequest, ChunkUploadResponse<ResponseT>> uploadChunkCallable,
UnaryCallable<QueryStatusRequest, QueryStatusResponse<ResponseT>> queryStatusCallable,
InputStream payload,
InputStreamSupplier payloadSupplier,
ResumableUploadOptions options,
ClientContext clientContext,
ExponentialRetryAlgorithm recoveryAlgorithm) {
checkNotNull(payloadSupplier, "payloadSupplier must not be null");
ResumableUploadFutureImpl<ResponseT> future =
new ResumableUploadFutureImpl<>(
startFuture,
uploadChunkCallable,
queryStatusCallable,
payload,
options,
clientContext,
recoveryAlgorithm);
try {
future.start();
future.start(payloadSupplier);
} catch (Throwable t) {
future.fail(t);
}
Expand All @@ -128,7 +128,6 @@
ApiFuture<ResumableUploadSession> startFuture,
UnaryCallable<ChunkUploadRequest, ChunkUploadResponse<ResponseT>> uploadChunkCallable,
UnaryCallable<QueryStatusRequest, QueryStatusResponse<ResponseT>> queryStatusCallable,
InputStream payload,
ResumableUploadOptions options,
ClientContext clientContext,
ExponentialRetryAlgorithm recoveryAlgorithm) {
Expand All @@ -137,7 +136,6 @@
checkNotNull(uploadChunkCallable, "uploadChunkCallable must not be null");
this.queryStatusCallable =
checkNotNull(queryStatusCallable, "queryStatusCallable must not be null");
this.payload = checkNotNull(payload, "payload must not be null");
this.options = checkNotNull(options, "options must not be null");
checkArgument(options.getChunkSize() > 0, "chunkSize must be > 0");
checkNotNull(clientContext, "clientContext must not be null");
Expand All @@ -151,11 +149,12 @@
}
}

private void start() {
private void start(InputStreamSupplier payloadSupplier) throws IOException {
Duration timeout = firstNonNull(options.getGlobalTimeout(), DEFAULT_GLOBAL_TIMEOUT);
ScheduledFuture<?> timeoutFuture =
executor.schedule(this::onTimeout, timeout.toMillis(), TimeUnit.MILLISECONDS);
resultFuture.addListener(() -> timeoutFuture.cancel(false), MoreExecutors.directExecutor());
this.payload = checkNotNull(payloadSupplier.get(), "payload supplier returned null");
ApiFutures.addCallback(
startFuture,
new ApiFutureCallback<ResumableUploadSession>() {
Expand Down Expand Up @@ -250,6 +249,9 @@
}

private void closePayload() {
if (payload == null) {
return;
}
try {
payload.close();
} catch (IOException ignored) {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.