From c5cc9ddd12a75ee75c047e92a70a9df3ec82a39f Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 19 Oct 2015 14:59:46 +0900 Subject: [PATCH] Import StandardCharsets.UTF_8 as static Change-Id: I066770f2eddfa7e9c1a67e91544006d33062d6d0 --- .../com/google/gerrit/acceptance/PluginDaemonTest.java | 5 +++-- .../java/com/google/gerrit/acceptance/RestResponse.java | 7 +++---- .../google/gerrit/acceptance/api/revision/RevisionIT.java | 6 +++--- .../com/google/gerrit/acceptance/edit/ChangeEditIT.java | 7 +++---- .../com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java | 4 ++-- .../com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java | 5 +++-- .../java/com/google/gerrit/pgm/init/InitAdminUser.java | 5 +++-- .../com/google/gerrit/sshd/commands/ReviewCommand.java | 6 +++--- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PluginDaemonTest.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PluginDaemonTest.java index f66494484e..f0b9f46afc 100644 --- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PluginDaemonTest.java +++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PluginDaemonTest.java @@ -14,6 +14,8 @@ package com.google.gerrit.acceptance; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.google.common.base.MoreObjects; import com.google.common.base.Strings; import com.google.gerrit.server.config.SitePaths; @@ -27,7 +29,6 @@ import java.io.IOException; import java.io.InputStream; import java.lang.ProcessBuilder.Redirect; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -134,7 +135,7 @@ public abstract class PluginDaemonTest extends AbstractDaemonTest { Path buckFile = pluginSource.resolve("BUCK"); byte[] bytes = Files.readAllBytes(buckFile); String buckContent = - new String(bytes, StandardCharsets.UTF_8).replaceAll("\\s+", ""); + new String(bytes, UTF_8).replaceAll("\\s+", ""); Matcher matcher = Pattern.compile("gerrit_plugin\\(name='(.*?)'").matcher(buckContent); if (matcher.find()) { diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/RestResponse.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/RestResponse.java index 6c7dbfee38..261b894ad4 100644 --- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/RestResponse.java +++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/RestResponse.java @@ -15,11 +15,11 @@ package com.google.gerrit.acceptance; import static com.google.gerrit.httpd.restapi.RestApiServlet.JSON_MAGIC; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; -import java.nio.charset.StandardCharsets; public class RestResponse extends HttpResponse { @@ -30,9 +30,8 @@ public class RestResponse extends HttpResponse { @Override public Reader getReader() throws IllegalStateException, IOException { if (reader == null && response.getEntity() != null) { - reader = - new InputStreamReader(response.getEntity().getContent(), - StandardCharsets.UTF_8); + reader = new InputStreamReader( + response.getEntity().getContent(), UTF_8); reader.skip(JSON_MAGIC.length); } return reader; diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java index 0289dcbccc..7ecf1f3e88 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java @@ -19,6 +19,7 @@ import static com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT; import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME; import static com.google.gerrit.acceptance.PushOneCommit.PATCH; import static org.eclipse.jgit.lib.Constants.HEAD; +import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; @@ -53,7 +54,6 @@ import org.junit.Before; import org.junit.Test; import java.io.ByteArrayOutputStream; -import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -429,7 +429,7 @@ public class RevisionIT extends AbstractDaemonTest { .content(); ByteArrayOutputStream os = new ByteArrayOutputStream(); bin.writeTo(os); - String res = new String(os.toByteArray(), StandardCharsets.UTF_8); + String res = new String(os.toByteArray(), UTF_8); assertThat(res).isEqualTo(FILE_CONTENT); } @@ -555,7 +555,7 @@ public class RevisionIT extends AbstractDaemonTest { .patch(); ByteArrayOutputStream os = new ByteArrayOutputStream(); bin.writeTo(os); - String res = new String(os.toByteArray(), StandardCharsets.UTF_8); + String res = new String(os.toByteArray(), UTF_8); ChangeInfo change = changeApi.get(); RevisionInfo rev = change.revisions.get(change.currentRevision); DateFormat df = new SimpleDateFormat( diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/edit/ChangeEditIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/edit/ChangeEditIT.java index 50bafbef84..625b33af0b 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/edit/ChangeEditIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/edit/ChangeEditIT.java @@ -77,7 +77,6 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; @@ -749,21 +748,21 @@ public class ChangeEditIT extends AbstractDaemonTest { private String newChange(PersonIdent ident) throws Exception { PushOneCommit push = pushFactory.create(db, ident, testRepo, PushOneCommit.SUBJECT, FILE_NAME, - new String(CONTENT_OLD, StandardCharsets.UTF_8)); + new String(CONTENT_OLD, UTF_8)); return push.to("refs/for/master").getChangeId(); } private String amendChange(PersonIdent ident, String changeId) throws Exception { PushOneCommit push = pushFactory.create(db, ident, testRepo, PushOneCommit.SUBJECT, FILE_NAME2, - new String(CONTENT_NEW2, StandardCharsets.UTF_8), changeId); + new String(CONTENT_NEW2, UTF_8), changeId); return push.to("refs/for/master").getChangeId(); } private String newChange2(PersonIdent ident) throws Exception { PushOneCommit push = pushFactory.create(db, ident, testRepo, PushOneCommit.SUBJECT, FILE_NAME, - new String(CONTENT_OLD, StandardCharsets.UTF_8)); + new String(CONTENT_OLD, UTF_8)); return push.rm("refs/for/master").getChangeId(); } diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java index c538b85d82..5d0e7dfaa7 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java @@ -15,6 +15,7 @@ package com.google.gerrit.acceptance.pgm; import static com.google.common.truth.Truth.assertThat; +import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.io.Files; import com.google.gerrit.launcher.GerritLauncher; @@ -26,7 +27,6 @@ import org.junit.Before; import org.junit.Test; import java.io.File; -import java.nio.charset.StandardCharsets; public class RebuildNotedbIT { private File sitePath; @@ -48,7 +48,7 @@ public class RebuildNotedbIT { initSite(); Files.append(NotesMigration.allEnabledConfig().toText(), new File(sitePath.toString(), "etc/gerrit.config"), - StandardCharsets.UTF_8); + UTF_8); runGerrit("RebuildNotedb", "-d", sitePath.toString(), "--show-stack-trace"); } diff --git a/gerrit-oauth/src/main/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java b/gerrit-oauth/src/main/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java index 2d736346a5..333af15968 100644 --- a/gerrit-oauth/src/main/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java +++ b/gerrit-oauth/src/main/java/com/google/gerrit/httpd/auth/oauth/OAuthWebFilter.java @@ -14,6 +14,8 @@ package com.google.gerrit.httpd.auth.oauth; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.google.common.base.MoreObjects; import com.google.common.base.Strings; import com.google.common.collect.Iterables; @@ -32,7 +34,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Set; import java.util.SortedMap; @@ -183,7 +184,7 @@ class OAuthWebFilter implements Filter { byte[] bin = HtmlDomUtil.toUTF8(doc); res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); res.setContentType("text/html"); - res.setCharacterEncoding(StandardCharsets.UTF_8.name()); + res.setCharacterEncoding(UTF_8.name()); res.setContentLength(bin.length); try (ServletOutputStream out = res.getOutputStream()) { out.write(bin); diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java index b670d39d8c..a09dcd577c 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitAdminUser.java @@ -14,6 +14,8 @@ package com.google.gerrit.pgm.init; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.google.common.base.Strings; import com.google.gerrit.common.TimeUtil; import com.google.gerrit.pgm.init.api.ConsoleUI; @@ -32,7 +34,6 @@ import com.google.inject.Inject; import org.apache.commons.validator.routines.EmailValidator; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -153,7 +154,7 @@ public class InitAdminUser implements InitStep { throw new IOException(String.format( "Cannot add public SSH key: %s is not a file", keyFile)); } - String content = new String(Files.readAllBytes(p), StandardCharsets.UTF_8); + String content = new String(Files.readAllBytes(p), UTF_8); return new AccountSshKey(new AccountSshKey.Id(id, 0), content); } } diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java index 1ca4c8c6fe..4570085edc 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java @@ -14,6 +14,8 @@ package com.google.gerrit.sshd.commands; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.google.common.base.Strings; import com.google.common.collect.Maps; import com.google.common.io.CharStreams; @@ -50,7 +52,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -249,8 +250,7 @@ public class ReviewCommand extends SshCommand { } private ReviewInput reviewFromJson() throws UnloggedFailure { - try (InputStreamReader r = - new InputStreamReader(in, StandardCharsets.UTF_8)) { + try (InputStreamReader r = new InputStreamReader(in, UTF_8)) { return OutputFormat.JSON.newGson(). fromJson(CharStreams.toString(r), ReviewInput.class); } catch (IOException | JsonSyntaxException e) {