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:
@@ -15,6 +15,7 @@
|
||||
|
||||
package com.google.gerrit.server.patch;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
@@ -297,7 +298,7 @@ public class PatchListLoader implements Callable<PatchList> {
|
||||
aCommit != null ? Text.forCommit(reader, aCommit) : Text.EMPTY;
|
||||
Text bText = Text.forCommit(reader, bCommit);
|
||||
|
||||
byte[] rawHdr = hdr.toString().getBytes("UTF-8");
|
||||
byte[] rawHdr = hdr.toString().getBytes(UTF_8);
|
||||
byte[] aContent = aText.getContent();
|
||||
byte[] bContent = bText.getContent();
|
||||
long sizeDelta = bContent.length - aContent.length;
|
||||
@@ -431,7 +432,7 @@ public class PatchListLoader implements Callable<PatchList> {
|
||||
MergeResult<? extends Sequence> p = entry.getValue();
|
||||
try (TemporaryBuffer buf =
|
||||
new TemporaryBuffer.LocalFile(null, 10 * 1024 * 1024)) {
|
||||
fmt.formatMerge(buf, p, "BASE", oursName, theirsName, "UTF-8");
|
||||
fmt.formatMerge(buf, p, "BASE", oursName, theirsName, UTF_8.name());
|
||||
buf.close();
|
||||
|
||||
try (InputStream in = buf.openInputStream()) {
|
||||
|
@@ -14,6 +14,9 @@
|
||||
|
||||
package com.google.gerrit.server.patch;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import org.eclipse.jgit.diff.RawText;
|
||||
import org.eclipse.jgit.errors.LargeObjectException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
@@ -37,7 +40,6 @@ import java.text.SimpleDateFormat;
|
||||
|
||||
public class Text extends RawText {
|
||||
private static final Logger log = LoggerFactory.getLogger(Text.class);
|
||||
private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
|
||||
private static final int bigFileThreshold = PackConfig.DEFAULT_BIG_FILE_THRESHOLD;
|
||||
|
||||
public static final byte[] NO_BYTES = {};
|
||||
@@ -81,7 +83,7 @@ public class Text extends RawText {
|
||||
appendPersonIdent(b, "Commit", c.getCommitterIdent());
|
||||
b.append("\n");
|
||||
b.append(c.getFullMessage());
|
||||
return new Text(b.toString().getBytes("UTF-8"));
|
||||
return new Text(b.toString().getBytes(UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user