aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-07-05 10:08:21 -0400
committerGravatar John Cater <jcater@google.com>2017-07-05 10:59:34 -0400
commit28f3b617f91f1a9ee9714b26f10d928ee4e1f970 (patch)
tree90c1de32fdecdbef279f2792e96d9fabf2d8190a /src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java
parente212c0514df05c5df8da097ff9ce443e0dde43e9 (diff)
Change the SimpleBlobStore API to use Input/OutputStreams
This avoid having to load all the data into memory at once in most cases, especially for large files. PiperOrigin-RevId: 160954187
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java b/src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java
index 898bd84c8a..60ff77b7bd 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/blobstore/RestBlobStore.java
@@ -13,8 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.remote.blobstore;
-import java.io.ByteArrayOutputStream;
+import com.google.common.io.ByteStreams;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@@ -79,7 +81,7 @@ public final class RestBlobStore implements SimpleBlobStore {
}
@Override
- public byte[] get(String key) throws IOException {
+ public boolean get(String key, OutputStream out) throws IOException {
HttpClient client = clientFactory.build();
HttpGet get = new HttpGet(baseUrl + "/" + key);
return client.execute(
@@ -88,22 +90,23 @@ public final class RestBlobStore implements SimpleBlobStore {
int statusCode = response.getStatusLine().getStatusCode();
if (HttpStatus.SC_NOT_FOUND == statusCode
|| HttpStatus.SC_NO_CONTENT == statusCode) {
- return null;
+ return false;
}
if (HttpStatus.SC_OK != statusCode) {
throw new IOException("GET failed with status code " + statusCode);
}
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- response.getEntity().writeTo(buffer);
- return buffer.toByteArray();
+ response.getEntity().writeTo(out);
+ return true;
});
}
@Override
- public void put(String key, byte[] value) throws IOException {
+ public void put(String key, InputStream in) throws IOException {
HttpClient client = clientFactory.build();
HttpPut put = new HttpPut(baseUrl + "/" + key);
- put.setEntity(new ByteArrayEntity(value));
+ // For now, upload a byte array instead of a stream, due to Hazelcast crashing on the stream.
+ // See https://github.com/hazelcast/hazelcast/issues/10878.
+ put.setEntity(new ByteArrayEntity(ByteStreams.toByteArray(in)));
put.setHeader("Content-Type", "application/octet-stream");
client.execute(
put,