Consistently use character encoding constants
Use the java.nio.charset.StandardCharsets.{ISO_8859_1,UTF_8} constants'
name() methods instead of hard-coding the strings.
Where possible, use method variants that take a Charset rather than
a String. This removes the need to catch UnsupportedEncodingException
in some cases.
Change-Id: I4ac1ba0a753de715e1f38ce631842f527b9e127c
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.pgm;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.gerrit.pgm.util.AbstractProgram;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gwtorm.schema.java.JavaSchemaModel;
|
||||
@@ -45,13 +47,13 @@ public class ProtoGen extends AbstractProgram {
|
||||
JavaSchemaModel jsm = new JavaSchemaModel(ReviewDb.class);
|
||||
try (OutputStream o = lock.getOutputStream();
|
||||
PrintWriter out = new PrintWriter(
|
||||
new BufferedWriter(new OutputStreamWriter(o, "UTF-8")))) {
|
||||
new BufferedWriter(new OutputStreamWriter(o, UTF_8)))) {
|
||||
String header;
|
||||
try (InputStream in = getClass().getResourceAsStream("ProtoGenHeader.txt")) {
|
||||
ByteBuffer buf = IO.readWholeStream(in, 1024);
|
||||
int ptr = buf.arrayOffset() + buf.position();
|
||||
int len = buf.remaining();
|
||||
header = new String(buf.array(), ptr, len, "UTF-8");
|
||||
header = new String(buf.array(), ptr, len, UTF_8);
|
||||
}
|
||||
|
||||
String version = com.google.gerrit.common.Version.getVersion();
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.pgm.init;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -120,7 +122,7 @@ class Libraries {
|
||||
if (in == null) {
|
||||
throw new FileNotFoundException("Cannot load resource " + p);
|
||||
}
|
||||
try (Reader r = new InputStreamReader(in, "UTF-8")) {
|
||||
try (Reader r = new InputStreamReader(in, UTF_8)) {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
final char[] tmp = new char[512];
|
||||
int n;
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.pgm.init;
|
||||
|
||||
import static com.google.gerrit.pgm.init.api.InitUtil.die;
|
||||
import static com.google.gerrit.pgm.init.api.InitUtil.savePublic;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.gerrit.pgm.init.api.ConsoleUI;
|
||||
import com.google.gerrit.pgm.init.api.InitFlags;
|
||||
@@ -172,8 +173,8 @@ class UpgradeFrom2_0_x implements InitStep {
|
||||
return false;
|
||||
}
|
||||
|
||||
String n = URLDecoder.decode(pair.substring(0, eq), "UTF-8");
|
||||
String v = URLDecoder.decode(pair.substring(eq + 1), "UTF-8");
|
||||
String n = URLDecoder.decode(pair.substring(0, eq), UTF_8.name());
|
||||
String v = URLDecoder.decode(pair.substring(eq + 1), UTF_8.name());
|
||||
|
||||
if ("user".equals(n) || "username".equals(n)) {
|
||||
username = v;
|
||||
|
||||
Reference in New Issue
Block a user