You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2014/10/10 15:13:56 UTC

[30/50] [abbrv] git commit: Migrate InputSupplier callers to ByteSource

Migrate InputSupplier callers to ByteSource

A future version of Guava will remove InputSupplier.


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/58021604
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/58021604
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/58021604

Branch: refs/heads/master
Commit: 58021604a96d1ceae4f83aac567f7c15129acb1d
Parents: 3b7d657
Author: Andrew Gaul <ga...@apache.org>
Authored: Sat May 17 00:42:21 2014 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Sat May 17 00:44:17 2014 -0700

----------------------------------------------------------------------
 .../java/org/jclouds/chef/config/BaseChefHttpApiModule.java  | 6 +++---
 .../main/java/org/jclouds/chef/config/ChefParserModule.java  | 8 ++++----
 .../org/jclouds/chef/functions/ParseClientFromJsonTest.java  | 6 ++++--
 3 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/58021604/apis/chef/src/main/java/org/jclouds/chef/config/BaseChefHttpApiModule.java
----------------------------------------------------------------------
diff --git a/apis/chef/src/main/java/org/jclouds/chef/config/BaseChefHttpApiModule.java b/apis/chef/src/main/java/org/jclouds/chef/config/BaseChefHttpApiModule.java
index c7816cb..83a9e29 100644
--- a/apis/chef/src/main/java/org/jclouds/chef/config/BaseChefHttpApiModule.java
+++ b/apis/chef/src/main/java/org/jclouds/chef/config/BaseChefHttpApiModule.java
@@ -62,7 +62,7 @@ import com.google.common.base.Supplier;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
-import com.google.common.io.ByteStreams;
+import com.google.common.io.ByteSource;
 import com.google.inject.ConfigurationException;
 import com.google.inject.Injector;
 import com.google.inject.Key;
@@ -137,7 +137,7 @@ public abstract class BaseChefHttpApiModule<S> extends HttpApiModule<S> {
       public PrivateKey load(Credentials in) {
          try {
             return crypto.rsaKeyFactory().generatePrivate(
-                  privateKeySpec(ByteStreams.newInputStreamSupplier(in.credential.getBytes(Charsets.UTF_8))));
+                  privateKeySpec(ByteSource.wrap(in.credential.getBytes(Charsets.UTF_8))));
          } catch (InvalidKeySpecException e) {
             throw propagate(e);
          } catch (IOException e) {
@@ -171,7 +171,7 @@ public abstract class BaseChefHttpApiModule<S> extends HttpApiModule<S> {
       try {
          String validatorCredential = injector.getInstance(key);
          PrivateKey validatorKey = crypto.rsaKeyFactory().generatePrivate(
-               Pems.privateKeySpec(ByteStreams.newInputStreamSupplier(validatorCredential.getBytes(Charsets.UTF_8))));
+               Pems.privateKeySpec(ByteSource.wrap(validatorCredential.getBytes(Charsets.UTF_8))));
          return Optional.<PrivateKey> of(validatorKey);
       } catch (ConfigurationException ex) {
          return Optional.<PrivateKey> absent();

http://git-wip-us.apache.org/repos/asf/jclouds/blob/58021604/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java
----------------------------------------------------------------------
diff --git a/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java b/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java
index 3e3f13e..baca929 100644
--- a/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java
+++ b/apis/chef/src/main/java/org/jclouds/chef/config/ChefParserModule.java
@@ -55,7 +55,7 @@ import com.google.common.base.Objects;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
-import com.google.common.io.ByteStreams;
+import com.google.common.io.ByteSource;
 import com.google.gson.Gson;
 import com.google.gson.JsonDeserializationContext;
 import com.google.gson.JsonDeserializer;
@@ -96,7 +96,7 @@ public class ChefParserModule extends AbstractModule {
          String keyText = json.getAsString().replaceAll("\\n", "\n");
          try {
             return crypto.rsaKeyFactory().generatePrivate(
-                  Pems.privateKeySpec(ByteStreams.newInputStreamSupplier(keyText.getBytes(Charsets.UTF_8))));
+                  Pems.privateKeySpec(ByteSource.wrap(keyText.getBytes(Charsets.UTF_8))));
          } catch (UnsupportedEncodingException e) {
             Throwables.propagate(e);
             return null;
@@ -130,7 +130,7 @@ public class ChefParserModule extends AbstractModule {
          String keyText = json.getAsString().replaceAll("\\n", "\n");
          try {
             return crypto.rsaKeyFactory().generatePublic(
-                  Pems.publicKeySpec(ByteStreams.newInputStreamSupplier(keyText.getBytes(Charsets.UTF_8))));
+                  Pems.publicKeySpec(ByteSource.wrap(keyText.getBytes(Charsets.UTF_8))));
          } catch (UnsupportedEncodingException e) {
             Throwables.propagate(e);
             return null;
@@ -163,7 +163,7 @@ public class ChefParserModule extends AbstractModule {
             throws JsonParseException {
          String keyText = json.getAsString().replaceAll("\\n", "\n");
          try {
-            return Pems.x509Certificate(ByteStreams.newInputStreamSupplier(keyText.getBytes(Charsets.UTF_8)),
+            return Pems.x509Certificate(ByteSource.wrap(keyText.getBytes(Charsets.UTF_8)),
                   crypto.certFactory());
          } catch (UnsupportedEncodingException e) {
             Throwables.propagate(e);

http://git-wip-us.apache.org/repos/asf/jclouds/blob/58021604/apis/chef/src/test/java/org/jclouds/chef/functions/ParseClientFromJsonTest.java
----------------------------------------------------------------------
diff --git a/apis/chef/src/test/java/org/jclouds/chef/functions/ParseClientFromJsonTest.java b/apis/chef/src/test/java/org/jclouds/chef/functions/ParseClientFromJsonTest.java
index 7685a95..e21fb15 100644
--- a/apis/chef/src/test/java/org/jclouds/chef/functions/ParseClientFromJsonTest.java
+++ b/apis/chef/src/test/java/org/jclouds/chef/functions/ParseClientFromJsonTest.java
@@ -39,6 +39,8 @@ import org.jclouds.rest.annotations.ApiVersion;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Charsets;
+import com.google.common.io.ByteSource;
 import com.google.common.io.ByteStreams;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
@@ -73,8 +75,8 @@ public class ParseClientFromJsonTest {
       handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Client>>() {
       }));
       crypto = injector.getInstance(Crypto.class);
-      certificate = Pems.x509Certificate(Payloads.newStringPayload(CERTIFICATE), null);
-      privateKey = crypto.rsaKeyFactory().generatePrivate(Pems.privateKeySpec(Payloads.newStringPayload(PRIVATE_KEY)));
+      certificate = Pems.x509Certificate(ByteSource.wrap(CERTIFICATE.getBytes(Charsets.UTF_8)), null);
+      privateKey = crypto.rsaKeyFactory().generatePrivate(Pems.privateKeySpec(ByteSource.wrap(PRIVATE_KEY.getBytes(Charsets.UTF_8))));
    }
 
    public void test() throws IOException {