Allow streaming remote upload to be sourced by an InputStream rather that a thread writing to an OutputStream. This is a pull mechanism.

PiperOrigin-RevId: 281514390
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploader.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploader.java
index d941f7e..3d4b1c6 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploader.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploader.java
@@ -21,10 +21,12 @@
 import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileType;
 import com.google.devtools.build.lib.vfs.Path;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.time.Duration;
 import java.util.Collection;
 import java.util.Map;
+import java.util.function.Supplier;
 import javax.annotation.Nullable;
 
 /** Uploads artifacts referenced by the Build Event Protocol (BEP). */
@@ -50,14 +52,22 @@
   interface UploadContext {
 
     /** The {@link OutputStream} to stream the file contents to. */
+    @Nullable
     OutputStream getOutputStream();
 
     /** The future URI of the completed upload. */
     ListenableFuture<String> uriFuture();
   }
 
-  /** Initiate a streaming upload to the remote storage. */
-  default UploadContext startUpload(LocalFileType type) {
+  /**
+   * Initiate a streaming upload to the remote storage.
+   *
+   * <p>If inputSupplier is null, the caller is expected to write to the {@link
+   * UploadContext#getOutputStream()}. If inputSupplier is non-null, {@link
+   * UploadContext#getOutputStream()} is null.
+   */
+  default UploadContext startUpload(
+      LocalFileType type, @Nullable Supplier<InputStream> inputSupplier) {
     return EMPTY_UPLOAD;
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
index 55a5b35..a00ec8e 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
@@ -327,7 +327,7 @@
           if (bepOptions.streamingLogFileUploads) {
             BuildEventArtifactUploader buildEventArtifactUploader =
                 newUploader(env, bepOptions.buildEventUploadStrategy);
-            streamingContext = buildEventArtifactUploader.startUpload(LocalFileType.LOG);
+            streamingContext = buildEventArtifactUploader.startUpload(LocalFileType.LOG, null);
             out = streamingContext.getOutputStream();
           } else {
             profilePath = workspace.getOutputBase().getRelative(profileName);