Prefer Guava Files over FileInputStream

This ensures proper resource handling.
This commit is contained in:
Andrew Gaul 2014-05-22 00:26:03 -07:00
parent a85b91904f
commit 289197a560
2 changed files with 8 additions and 7 deletions

View File

@ -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;

View File

@ -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();
}