Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use StandardCharsets.UTF_8 constant #532

Merged
merged 5 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -153,7 +154,7 @@ public static GoogleCredentials fromStream(
JsonFactory jsonFactory = OAuth2Utils.JSON_FACTORY;
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
GenericJson fileContents =
parser.parseAndClose(credentialsStream, OAuth2Utils.UTF_8, GenericJson.class);
parser.parseAndClose(credentialsStream, StandardCharsets.UTF_8, GenericJson.class);

String fileType = (String) fileContents.get("type");
if (fileType == null) {
Expand Down
3 changes: 0 additions & 3 deletions oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
Expand All @@ -68,8 +67,6 @@ class OAuth2Utils {

static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();

static final Charset UTF_8 = Charset.forName("UTF-8");

private static String VALUE_NOT_FOUND_MESSAGE = "%sExpected value %s not found.";
private static String VALUE_WRONG_TYPE_MESSAGE = "%sExpected %s value %s of wrong type.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
Expand Down Expand Up @@ -377,7 +378,7 @@ public static ServiceAccountCredentials fromStream(
JsonFactory jsonFactory = OAuth2Utils.JSON_FACTORY;
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
GenericJson fileContents =
parser.parseAndClose(credentialsStream, OAuth2Utils.UTF_8, GenericJson.class);
parser.parseAndClose(credentialsStream, StandardCharsets.UTF_8, GenericJson.class);

String fileType = (String) fileContents.get("type");
if (fileType == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
Expand Down Expand Up @@ -250,7 +251,7 @@ public static ServiceAccountJwtAccessCredentials fromStream(
JsonFactory jsonFactory = OAuth2Utils.JSON_FACTORY;
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
GenericJson fileContents =
parser.parseAndClose(credentialsStream, OAuth2Utils.UTF_8, GenericJson.class);
parser.parseAndClose(credentialsStream, StandardCharsets.UTF_8, GenericJson.class);

String fileType = (String) fileContents.get("type");
if (fileType == null) {
Expand Down
6 changes: 3 additions & 3 deletions oauth2_http/java/com/google/auth/oauth2/UserCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
package com.google.auth.oauth2;

import static com.google.auth.oauth2.OAuth2Utils.JSON_FACTORY;
import static com.google.auth.oauth2.OAuth2Utils.UTF_8;
import static com.google.common.base.MoreObjects.firstNonNull;

import com.google.api.client.http.GenericUrl;
Expand All @@ -52,6 +51,7 @@
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -167,7 +167,7 @@ public static UserCredentials fromStream(
JsonFactory jsonFactory = JSON_FACTORY;
JsonObjectParser parser = new JsonObjectParser(jsonFactory);
GenericJson fileContents =
parser.parseAndClose(credentialsStream, OAuth2Utils.UTF_8, GenericJson.class);
parser.parseAndClose(credentialsStream, StandardCharsets.UTF_8, GenericJson.class);

String fileType = (String) fileContents.get("type");
if (fileType == null) {
Expand Down Expand Up @@ -263,7 +263,7 @@ private InputStream getUserCredentialsStream() throws IOException {
}
json.setFactory(JSON_FACTORY);
String text = json.toPrettyString();
return new ByteArrayInputStream(text.getBytes(UTF_8));
return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
}

/**
Expand Down