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 2015/04/15 21:41:22 UTC

[17/39] jclouds git commit: Prefer Guava Files over FileInputStream

Prefer Guava Files over FileInputStream

This ensures proper resource handling.


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

Branch: refs/heads/master
Commit: 289197a560934e3c2e4a5b43936b419512d5f0cc
Parents: a85b919
Author: Andrew Gaul <ga...@apache.org>
Authored: Thu May 22 00:26:03 2014 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Thu May 22 00:26:03 2014 -0700

----------------------------------------------------------------------
 .../src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java  | 6 ++----
 .../oauth/v2/functions/OAuthCredentialsFromPKTest.java      | 9 ++++++---
 2 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/289197a5/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
index 611a60a..35eb9b1 100644
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
+++ b/apis/oauth/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java
@@ -19,10 +19,8 @@ package org.jclouds.oauth.v2;
 import com.google.common.base.Charsets;
 import com.google.common.base.Throwables;
 import com.google.common.io.Files;
-import org.jclouds.util.Strings2;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Properties;
 
@@ -40,8 +38,8 @@ public class OAuthTestUtils {
       try {
          properties = properties == null ? new Properties() : properties;
          properties.put("oauth.identity", "foo");
-         properties.put("oauth.credential", Strings2.toStringAndClose(new FileInputStream("src/test/resources/testpk" +
-                 ".pem")));
+         properties.put("oauth.credential",
+            Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read());
          properties.put("oauth.endpoint", "http://localhost:5000/o/oauth2/token");
          properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token");
          return properties;

http://git-wip-us.apache.org/repos/asf/jclouds/blob/289197a5/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java
----------------------------------------------------------------------
diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java
index 435cabcd..e3794d6 100644
--- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java
+++ b/apis/oauth/src/test/java/org/jclouds/oauth/v2/functions/OAuthCredentialsFromPKTest.java
@@ -17,11 +17,10 @@
 package org.jclouds.oauth.v2.functions;
 
 import static com.google.common.base.Suppliers.ofInstance;
-import static org.jclouds.util.Strings2.toStringAndClose;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 
-import java.io.FileInputStream;
+import java.io.File;
 import java.io.IOException;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
@@ -29,6 +28,9 @@ import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.security.spec.InvalidKeySpecException;
 
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
 import org.jclouds.domain.Credentials;
 import org.jclouds.oauth.v2.domain.OAuthCredentials;
 import org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier.OAuthCredentialsForCredentials;
@@ -43,7 +45,8 @@ public class OAuthCredentialsFromPKTest {
    public static OAuthCredentials loadOAuthCredentials() throws IOException, NoSuchAlgorithmException,
          CertificateException, InvalidKeySpecException {
       OAuthCredentialsSupplier loader = new OAuthCredentialsSupplier(ofInstance(new Credentials("foo",
-            toStringAndClose(new FileInputStream("src/test/resources/testpk.pem")))), new OAuthCredentialsForCredentials("RS256"), "RS256");
+            Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read())),
+            new OAuthCredentialsForCredentials("RS256"), "RS256");
       return loader.get();
    }