Skip to content

Commit

Permalink
chore: there's now a UTF-8 constant in the JDK (#532)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
elharo and chingor13 committed Jan 5, 2021
1 parent ecfc6a2 commit a8697f7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
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
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
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
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
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

0 comments on commit a8697f7

Please sign in to comment.