From 011aed71ed9143be8f59973cacf23df98a9d49a8 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 22 Jul 2014 16:50:46 -0700 Subject: [PATCH] Prefer ByteStreams2 over ByteSources.asByteSource The latter breaks the contract of ByteSource which specifies that openStream can produce multiple independent streams. --- .../main/java/org/jclouds/chef/filters/SignedHeaderAuth.java | 4 ++-- .../java/org/jclouds/chef/internal/BaseChefApiLiveTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apis/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java b/apis/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java index 7d789bb201..cabe579b3a 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java +++ b/apis/chef/src/main/java/org/jclouds/chef/filters/SignedHeaderAuth.java @@ -42,7 +42,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpUtils; import org.jclouds.http.internal.SignatureWire; -import org.jclouds.io.ByteSources; +import org.jclouds.io.ByteStreams2; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.io.payloads.MultipartForm; @@ -162,7 +162,7 @@ public class SignedHeaderAuth implements HttpRequestFilter { checkArgument(payload != null, "payload was null"); checkArgument(payload.isRepeatable(), "payload must be repeatable: " + payload); try { - return base64().encode(ByteSources.asByteSource(payload.getInput()).hash(sha1()).asBytes()); + return base64().encode(ByteStreams2.hashAndClose(payload.getInput(), sha1()).asBytes()); } catch (Exception e) { Throwables.propagateIfPossible(e); throw new HttpException("error creating sigature for payload: " + payload, e); diff --git a/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java b/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java index 2d04dcd302..b57499c262 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java @@ -21,7 +21,6 @@ import static com.google.common.collect.Iterables.any; import static com.google.common.collect.Iterables.isEmpty; import static com.google.common.hash.Hashing.md5; import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.jclouds.io.ByteSources.asByteSource; import static org.jclouds.util.Predicates2.retry; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -55,6 +54,7 @@ import org.jclouds.chef.domain.UploadSandbox; import org.jclouds.chef.options.CreateClientOptions; import org.jclouds.chef.options.SearchOptions; import org.jclouds.crypto.Pems; +import org.jclouds.io.ByteStream2; import org.jclouds.io.Payloads; import org.jclouds.io.payloads.FilePayload; import org.jclouds.rest.ResourceNotFoundException; @@ -167,7 +167,7 @@ public abstract class BaseChefApiLiveTest extends BaseChefLiv InputStream stream = api.getResourceContents(resource); assertNotNull(stream, "Resource contents are null for resource: " + resource.getName()); - byte[] md5 = asByteSource(stream).hash(md5()).asBytes(); + byte[] md5 = ByteStream2.hashAndClose(stream, md5()).asBytes(); assertEquals(md5, resource.getChecksum()); } }