Import StandardCharsets.UTF_8 as static

Change-Id: I066770f2eddfa7e9c1a67e91544006d33062d6d0
This commit is contained in:
David Pursehouse 2015-10-19 14:59:46 +09:00
parent 7f6601429a
commit c5cc9ddd12
8 changed files with 23 additions and 22 deletions

View File

@ -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()) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) {