From 171f84a04117cfd02446f67565073a05128777a4 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 Dec 2017 10:23:38 +0900 Subject: Use constants from StandardCharsets instead of hard-coded strings Instead of hard-coding the charset strings "US-ASCII", "UTF-8", and "ISO-8859-1", use the corresponding constants from StandardCharsets. UnsupportedEncodingException is not thrown when the StandardCharset constants are used, so remove the now redundant handling. Because the encoding names are no longer hard-coded strings, also remove redundant $NON-NLS warning suppressions. Also replace existing usages of the constants with static imports. Change-Id: I0a4510d3d992db5e277f009a41434276f95bda4e Signed-off-by: David Pursehouse --- .../jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java | 11 +++++------ .../exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'org.eclipse.jgit.test/exttst') diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java index e5a80aeefa..03b34acc05 100644 --- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java +++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java @@ -42,13 +42,14 @@ */ package org.eclipse.jgit.ignore; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.Arrays; @@ -153,13 +154,11 @@ public class CGitVsJGitRandomIgnorePatternTest { private String pattern; - public CGitIgnoreRule(File gitDir, String pattern) - throws UnsupportedEncodingException, IOException { + public CGitIgnoreRule(File gitDir, String pattern) throws IOException { this.gitDir = gitDir; this.pattern = pattern; Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")), - (pattern + "\n").getBytes("UTF-8"), - StandardOpenOption.CREATE, + (pattern + "\n").getBytes(UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE); } @@ -189,7 +188,7 @@ public class CGitVsJGitRandomIgnorePatternTest { Process proc = Runtime.getRuntime().exec(command, new String[0], gitDir); OutputStream out = proc.getOutputStream(); - out.write((path + "\n").getBytes("UTF-8")); + out.write((path + "\n").getBytes(UTF_8)); out.flush(); out.close(); return proc; diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java index 7c0ea44c35..586505cfe8 100644 --- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java +++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.patch; +import static java.nio.charset.StandardCharsets.ISO_8859_1; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -218,7 +219,7 @@ public class EGitPatchHistoryTest { commitId = line.substring("commit ".length()); buf = new TemporaryBuffer.LocalFile(null); } else if (buf != null) { - buf.write(line.getBytes("ISO-8859-1")); + buf.write(line.getBytes(ISO_8859_1)); buf.write('\n'); } } -- cgit v1.2.3