Use Java 7 StandardCharsets instead of Guava Charsets

Replace with static imports since the class name is so much longer.

Change-Id: If2cdede62a0977db05db69b4c9ec88bd980e011f
This commit is contained in:
Dave Borowitz 2014-01-27 16:59:31 -08:00
parent c6f7459d92
commit 68a55b9074
9 changed files with 29 additions and 24 deletions

View File

@ -14,9 +14,10 @@
package com.google.gerrit.httpd.restapi;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.math.RoundingMode.CEILING;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_CONFLICT;
import static javax.servlet.http.HttpServletResponse.SC_CREATED;
@ -28,7 +29,6 @@ import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_PRECONDITION_FAILED;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
@ -737,7 +737,7 @@ public class RestApiServlet extends HttpServlet {
@Override
public void writeTo(OutputStream out) throws IOException {
OutputStream e = BaseEncoding.base64().encodingStream(
new OutputStreamWriter(out, Charsets.ISO_8859_1));
new OutputStreamWriter(out, ISO_8859_1));
src.writeTo(e);
e.flush();
}
@ -957,7 +957,7 @@ public class RestApiServlet extends HttpServlet {
int max = 4 * IntMath.divide((int) bin.getContentLength(), 3, CEILING);
TemporaryBuffer.Heap buf = heap(max);
OutputStream encoded = BaseEncoding.base64().encodingStream(
new OutputStreamWriter(buf, Charsets.ISO_8859_1));
new OutputStreamWriter(buf, ISO_8859_1));
bin.writeTo(encoded);
encoded.close();
return asBinaryResult(buf);

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.account;
import com.google.common.base.Charsets;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.io.ByteSource;
import com.google.gerrit.common.errors.InvalidSshKeyException;
import com.google.gerrit.extensions.restapi.AuthException;
@ -79,7 +80,7 @@ public class AddSshKey implements RestModifyView<AccountResource, Input> {
public InputStream openStream() throws IOException {
return rawKey.getInputStream();
}
}.asCharSource(Charsets.UTF_8).read();
}.asCharSource(UTF_8).read();
try {
AccountSshKey sshKey =

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Charsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.ResourceConflictException;

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.change;
import com.google.common.base.Charsets;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
@ -98,7 +99,7 @@ public class TestSubmitRule implements RestModifyView<RevisionResource, Input> {
"locate_submit_filter", "filter_submit_results",
input.filters == Filters.SKIP,
input.rule != null
? new ByteArrayInputStream(input.rule.getBytes(Charsets.UTF_8))
? new ByteArrayInputStream(input.rule.getBytes(UTF_8))
: null);
List<Term> results;

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.change;
import com.google.common.base.Charsets;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Objects;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
@ -78,7 +79,7 @@ public class TestSubmitType implements RestModifyView<RevisionResource, Input> {
"locate_submit_type_filter", "filter_submit_type_results",
input.filters == Filters.SKIP,
input.rule != null
? new ByteArrayInputStream(input.rule.getBytes(Charsets.UTF_8))
? new ByteArrayInputStream(input.rule.getBytes(UTF_8))
: null);
List<Term> results;

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.mail;
import com.google.common.base.Charsets;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.gerrit.common.data.ParameterizedString;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.GerritPersonIdent;
@ -179,7 +180,7 @@ public class FromAddressGeneratorProvider implements
private static String hashOf(String data) {
try {
MessageDigest hash = MessageDigest.getInstance("MD5");
byte[] bytes = hash.digest(data.getBytes(Charsets.UTF_8));
byte[] bytes = hash.digest(data.getBytes(UTF_8));
return Base64.encodeBase64URLSafeString(bytes);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("No MD5 available", e);

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.project;
import com.google.common.base.Charsets;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.gerrit.common.data.GarbageCollectionResult;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.extensions.annotations.RequiresCapability;
@ -58,7 +59,7 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input>,
@Override
public void writeTo(OutputStream out) throws IOException {
PrintWriter writer = new PrintWriter(
new OutputStreamWriter(out, Charsets.UTF_8)) {
new OutputStreamWriter(out, UTF_8)) {
@Override
public void println() {
write('\n');
@ -94,7 +95,7 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input>,
}
}
}.setContentType("text/plain")
.setCharacterEncoding(Charsets.UTF_8.name())
.setCharacterEncoding(UTF_8.name())
.disableGzip();
}

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.project;
import com.google.common.base.Charsets;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
@ -30,8 +31,8 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.rules.PrologEnvironment;
import com.google.gerrit.rules.RulesCache;
import com.google.gerrit.server.CurrentUser;
@ -482,7 +483,7 @@ public class ProjectState {
}
private String readFile(File f) throws IOException {
return f.exists() ? Files.toString(f, Charsets.UTF_8) : null;
return f.exists() ? Files.toString(f, UTF_8) : null;
}
private boolean getInheritableBoolean(Function<Project, InheritableBoolean> func) {

View File

@ -14,14 +14,13 @@
package com.google.gerrit.server.query.change;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -681,10 +680,10 @@ public abstract class AbstractQueryChangesTest {
if (key == null) {
key = "I" + Hashing.sha1().newHasher()
.putInt(id.get())
.putString(project.get(), Charsets.UTF_8)
.putString(commit.name(), Charsets.UTF_8)
.putString(project.get(), UTF_8)
.putString(commit.name(), UTF_8)
.putInt(ownerId.get())
.putString(branch, Charsets.UTF_8)
.putString(branch, UTF_8)
.hash()
.toString();
}