]> source.dussan.org Git - jgit.git/commitdiff
Use constants from StandardCharsets instead of hard-coded strings 80/112980/5
authorDavid Pursehouse <david.pursehouse@gmail.com>
Thu, 7 Dec 2017 01:23:38 +0000 (10:23 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Thu, 7 Dec 2017 11:02:59 +0000 (20:02 +0900)
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 <david.pursehouse@gmail.com>
36 files changed:
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java
org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java
org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/errors/InvalidLongObjectIdException.java
org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java
org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java

index 51b79903c6514337cfd52331939dab1bd7c193c2..5f40be4e05cbf864d5e1e9da162b10c1a08df72c 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.http.test;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING;
 import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH;
 import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE;
@@ -56,7 +57,6 @@ import static org.junit.Assert.fail;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.URISyntaxException;
-import java.nio.charset.StandardCharsets;
 import java.text.MessageFormat;
 import java.util.Arrays;
 import java.util.Collection;
@@ -1084,7 +1084,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
        public void testInvalidWant() throws Exception {
                @SuppressWarnings("resource")
                ObjectId id = new ObjectInserter.Formatter().idFor(Constants.OBJ_BLOB,
-                               "testInvalidWant".getBytes(StandardCharsets.UTF_8));
+                               "testInvalidWant".getBytes(UTF_8));
 
                Repository dst = createBareRepository();
                try (Transport t = Transport.open(dst, remoteURI);
index 382afc5cae54fb93078c93ec1284f916debe3ab7..db6f60960cfe91a082fc97a0f0d95e6d43c513fb 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.junit;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
@@ -246,7 +247,7 @@ public class TestRepository<R extends Repository> {
         * @throws Exception
         */
        public RevBlob blob(final String content) throws Exception {
-               return blob(content.getBytes("UTF-8"));
+               return blob(content.getBytes(UTF_8));
        }
 
        /**
index a9b0ec46e41ac816582af0dc97513384c8da5f6a..b21c94e4e6488640fba293ca952f216962a653fc 100644 (file)
  */
 package org.eclipse.jgit.lfs.server.s3;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
@@ -359,13 +359,13 @@ class SignerV4 {
 
        private static byte[] hash(String s) {
                MessageDigest md = Constants.newMessageDigest();
-               md.update(s.getBytes(StandardCharsets.UTF_8));
+               md.update(s.getBytes(UTF_8));
                return md.digest();
        }
 
        private static byte[] sign(String stringData, byte[] key) {
                try {
-                       byte[] data = stringData.getBytes("UTF-8"); //$NON-NLS-1$
+                       byte[] data = stringData.getBytes(UTF_8);
                        Mac mac = Mac.getInstance(HMACSHA256);
                        mac.init(new SecretKeySpec(key, HMACSHA256));
                        return mac.doFinal(data);
@@ -395,7 +395,7 @@ class SignerV4 {
        private static String urlEncode(String url, boolean keepPathSlash) {
                String encoded;
                try {
-                       encoded = URLEncoder.encode(url, StandardCharsets.UTF_8.name());
+                       encoded = URLEncoder.encode(url, UTF_8.name());
                } catch (UnsupportedEncodingException e) {
                        throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e);
                }
index 6c6400f2934852d9446383b662cab21ed62f46b0..c3c38594675bf10c9d79531e68393047483b6230 100644 (file)
  */
 package org.eclipse.jgit.lfs.test;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.io.BufferedInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.security.MessageDigest;
@@ -65,7 +66,7 @@ public class LongObjectIdTestUtils {
         */
        public static LongObjectId hash(String s) {
                MessageDigest md = Constants.newMessageDigest();
-               md.update(s.getBytes(StandardCharsets.UTF_8));
+               md.update(s.getBytes(UTF_8));
                return LongObjectId.fromRaw(md.digest());
        }
 
index 4827d3d113c257a2cbd6e8200d98b6397d6e2394..2ace2e3ce68d86e3e2ec4df542b7584363128715 100644 (file)
 
 package org.eclipse.jgit.lfs.lib;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
 
 import org.eclipse.jgit.lfs.LfsPointer;
 import org.junit.Test;
@@ -66,6 +66,6 @@ public class LFSPointerTest {
                baos.close();
                assertEquals("version https://git-lfs.github.com/spec/v1\noid sha256:"
                                + s + "\nsize 4\n",
-                               baos.toString(StandardCharsets.UTF_8.name()));
+                               baos.toString(UTF_8.name()));
        }
 }
index 31ab783e2a2c7ba830ed53d25135d418e7477908..d6dd3aa6077e471386d42a46802c4ee49d37c77d 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.lfs.lib;
 
+import static java.nio.charset.StandardCharsets.US_ASCII;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
@@ -54,7 +55,6 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Locale;
@@ -270,7 +270,7 @@ public class LongObjectIdTest {
        public void testCopyFromStringByte() {
                AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
                byte[] buf = new byte[64];
-               Charset cs = StandardCharsets.US_ASCII;
+               Charset cs = US_ASCII;
                cs.encode(id1.name()).get(buf);
                AnyLongObjectId id2 = LongObjectId.fromString(buf, 0);
                assertEquals("objects should be equals", id1, id2);
index 0f62025be55a25263c626a66c7815d517bd7e5c8..56e798744313a9b02a197dde090750cf55c0a3ef 100644 (file)
@@ -42,6 +42,8 @@
  */
 package org.eclipse.jgit.lfs;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
@@ -49,7 +51,6 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.Locale;
 
@@ -120,7 +121,7 @@ public class LfsPointer {
         */
        public void encode(OutputStream out) {
                try (PrintStream ps = new PrintStream(out, false,
-                               StandardCharsets.UTF_8.name())) {
+                               UTF_8.name())) {
                        ps.print("version "); //$NON-NLS-1$
                        ps.print(VERSION + "\n"); //$NON-NLS-1$
                        ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -129,8 +130,7 @@ public class LfsPointer {
                        ps.print(size + "\n"); //$NON-NLS-1$
                } catch (UnsupportedEncodingException e) {
                        // should not happen, we are using a standard charset
-                       throw new UnsupportedCharsetException(
-                                       StandardCharsets.UTF_8.name());
+                       throw new UnsupportedCharsetException(UTF_8.name());
                }
        }
 
@@ -152,7 +152,7 @@ public class LfsPointer {
                long sz = -1;
 
                try (BufferedReader br = new BufferedReader(
-                               new InputStreamReader(in, StandardCharsets.UTF_8.name()))) {
+                               new InputStreamReader(in, UTF_8))) {
                        for (String s = br.readLine(); s != null; s = br.readLine()) {
                                if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$
                                        continue;
index 44ac317a16c9526ce39d05541465e63e18da1308..ee33d905dcfdcc50876b73f2921f2a37ac847ea7 100644 (file)
@@ -45,7 +45,8 @@
 
 package org.eclipse.jgit.lfs.errors;
 
-import java.io.UnsupportedEncodingException;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+
 import java.text.MessageFormat;
 
 import org.eclipse.jgit.lfs.internal.LfsText;
@@ -80,10 +81,8 @@ public class InvalidLongObjectIdException extends IllegalArgumentException {
 
        private static String asAscii(byte[] bytes, int offset, int length) {
                try {
-                       return new String(bytes, offset, length, "US-ASCII"); //$NON-NLS-1$
-               } catch (UnsupportedEncodingException e2) {
-                       return ""; //$NON-NLS-1$
-               } catch (StringIndexOutOfBoundsException e2) {
+                       return new String(bytes, offset, length, US_ASCII);
+               } catch (StringIndexOutOfBoundsException e) {
                        return ""; //$NON-NLS-1$
                }
        }
index e5a80aeefa69c20883eb91816e67fadb03607de0..03b34acc05542fafabe4d590e4e8df58609acd3d 100644 (file)
  */
 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;
index 7c0ea44c355baff950b4fc63891797f7363df961..586505cfe81a1faa55895b83575e1e23c3046d4e 100644 (file)
@@ -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');
                                }
                        }
index 2ee77a010a8989173e1e45088f1244ff5e1db25e..1e3a39aad82b301a12d2e7069a777322443557ea 100644 (file)
@@ -42,6 +42,7 @@
 
 package org.eclipse.jgit.api;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF;
 import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF;
 import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT;
@@ -53,7 +54,6 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.eclipse.jgit.lib.CoreConfig.EolStreamType;
@@ -150,9 +150,8 @@ public class EolStreamTypeUtilTest {
                        EolStreamType streamTypeWithBinaryCheck, String output,
                        String expectedConversion) throws Exception {
                ByteArrayOutputStream b;
-               byte[] outputBytes = output.getBytes(StandardCharsets.UTF_8);
-               byte[] expectedConversionBytes = expectedConversion
-                               .getBytes(StandardCharsets.UTF_8);
+               byte[] outputBytes = output.getBytes(UTF_8);
+               byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
 
                // test using output text and assuming it was declared TEXT
                b = new ByteArrayOutputStream();
@@ -278,9 +277,8 @@ public class EolStreamTypeUtilTest {
        private void testCheckin(EolStreamType streamTypeText,
                        EolStreamType streamTypeWithBinaryCheck, String input,
                        String expectedConversion) throws Exception {
-               byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8);
-               byte[] expectedConversionBytes = expectedConversion
-                               .getBytes(StandardCharsets.UTF_8);
+               byte[] inputBytes = input.getBytes(UTF_8);
+               byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
 
                // test using input text and assuming it was declared TEXT
                try (InputStream in = EolStreamTypeUtil.wrapInputStream(
index a34128485097d7fcfbc351b3cb9150656457dbc9..cc5a0249cb256700787f28776b585aad8c42d4ee 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.api;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -593,7 +594,7 @@ public class PullCommandTest extends RepositoryTestCase {
                FileOutputStream fos = null;
                try {
                        fos = new FileOutputStream(actFile);
-                       fos.write(string.getBytes("UTF-8"));
+                       fos.write(string.getBytes(UTF_8));
                        fos.close();
                } finally {
                        if (fos != null)
index 6f6b1158ebb63e57fa20e6c47db768d294aeb655..dfe05b808ec4959b117fc4fb7afd8202d225f35f 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.api;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -397,7 +398,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
                FileOutputStream fos = null;
                try {
                        fos = new FileOutputStream(actFile);
-                       fos.write(string.getBytes("UTF-8"));
+                       fos.write(string.getBytes(UTF_8));
                        fos.close();
                } finally {
                        if (fos != null)
index 0cc0816c1628f0a537336ca1d0d9bad9b116dbe8..3f43c6b1bbf3e550cac7e9372a87eab5bf54bcc0 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.api;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -1463,7 +1464,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
                assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]);
 
                PersonIdent parsedIdent = git.rebase().parseAuthor(
-                               convertedAuthor.getBytes("UTF-8"));
+                               convertedAuthor.getBytes(UTF_8));
                assertEquals(ident.getName(), parsedIdent.getName());
                assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
                // this is rounded to the last second
@@ -1480,7 +1481,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
                assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]);
 
                parsedIdent = git.rebase().parseAuthor(
-                               convertedAuthor.getBytes("UTF-8"));
+                               convertedAuthor.getBytes(UTF_8));
                assertEquals(ident.getName(), parsedIdent.getName());
                assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
                assertEquals(123456789000L, parsedIdent.getWhen().getTime());
index 4130b7ee5b591af8bb8a1ffdd4dbf3cf04feee3b..0f13a68b256c870a6063921cc8686feec66e4bac 100644 (file)
 
 package org.eclipse.jgit.diff;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.io.UnsupportedEncodingException;
-
 import org.junit.Test;
 
 public abstract class AbstractDiffTestCase {
@@ -241,10 +240,6 @@ public abstract class AbstractDiffTestCase {
                        r.append(text.charAt(i));
                        r.append('\n');
                }
-               try {
-                       return new RawText(r.toString().getBytes("UTF-8"));
-               } catch (UnsupportedEncodingException e) {
-                       throw new RuntimeException(e);
-               }
+               return new RawText(r.toString().getBytes(UTF_8));
        }
 }
index 93ea9a7ab566d620479543cb9c83a06a4116e5f8..6ad59b9e56498b527c3da29ad9e1c0957ac49971 100644 (file)
@@ -44,6 +44,7 @@
 
 package org.eclipse.jgit.diff;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
@@ -51,7 +52,6 @@ import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.util.RawParseUtils;
@@ -110,8 +110,7 @@ public class RawTextTest {
        }
 
        @Test
-       public void testComparatorReduceCommonStartEnd()
-                       throws UnsupportedEncodingException {
+       public void testComparatorReduceCommonStartEnd() {
                final RawTextComparator c = RawTextComparator.DEFAULT;
                Edit e;
 
@@ -137,54 +136,51 @@ public class RawTextTest {
                e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e);
                assertEquals(new Edit(2, 3, 2, 3), e);
 
-               RawText a = new RawText("p\na b\nQ\nc d\n".getBytes("UTF-8"));
-               RawText b = new RawText("p\na  b \nR\n c  d \n".getBytes("UTF-8"));
+               RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(UTF_8));
+               RawText b = new RawText("p\na  b \nR\n c  d \n".getBytes(UTF_8));
                e = new Edit(0, 4, 0, 4);
                e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e);
                assertEquals(new Edit(2, 3, 2, 3), e);
        }
 
        @Test
-       public void testComparatorReduceCommonStartEnd_EmptyLine()
-                       throws UnsupportedEncodingException {
+       public void testComparatorReduceCommonStartEnd_EmptyLine() {
                RawText a;
                RawText b;
                Edit e;
 
-               a = new RawText("R\n y\n".getBytes("UTF-8"));
-               b = new RawText("S\n\n y\n".getBytes("UTF-8"));
+               a = new RawText("R\n y\n".getBytes(UTF_8));
+               b = new RawText("S\n\n y\n".getBytes(UTF_8));
                e = new Edit(0, 2, 0, 3);
                e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
                assertEquals(new Edit(0, 1, 0, 2), e);
 
-               a = new RawText("S\n\n y\n".getBytes("UTF-8"));
-               b = new RawText("R\n y\n".getBytes("UTF-8"));
+               a = new RawText("S\n\n y\n".getBytes(UTF_8));
+               b = new RawText("R\n y\n".getBytes(UTF_8));
                e = new Edit(0, 3, 0, 2);
                e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
                assertEquals(new Edit(0, 2, 0, 1), e);
        }
 
        @Test
-       public void testComparatorReduceCommonStartButLastLineNoEol()
-                       throws UnsupportedEncodingException {
+       public void testComparatorReduceCommonStartButLastLineNoEol() {
                RawText a;
                RawText b;
                Edit e;
-               a = new RawText("start".getBytes("UTF-8"));
-               b = new RawText("start of line".getBytes("UTF-8"));
+               a = new RawText("start".getBytes(UTF_8));
+               b = new RawText("start of line".getBytes(UTF_8));
                e = new Edit(0, 1, 0, 1);
                e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
                assertEquals(new Edit(0, 1, 0, 1), e);
        }
 
        @Test
-       public void testComparatorReduceCommonStartButLastLineNoEol_2()
-                       throws UnsupportedEncodingException {
+       public void testComparatorReduceCommonStartButLastLineNoEol_2() {
                RawText a;
                RawText b;
                Edit e;
-               a = new RawText("start".getBytes("UTF-8"));
-               b = new RawText("start of\nlastline".getBytes("UTF-8"));
+               a = new RawText("start".getBytes(UTF_8));
+               b = new RawText("start of\nlastline".getBytes(UTF_8));
                e = new Edit(0, 1, 0, 2);
                e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
                assertEquals(new Edit(0, 1, 0, 2), e);
@@ -243,10 +239,6 @@ public class RawTextTest {
                        r.append(text.charAt(i));
                        r.append('\n');
                }
-               try {
-                       return new RawText(r.toString().getBytes("UTF-8"));
-               } catch (UnsupportedEncodingException e) {
-                       throw new RuntimeException(e);
-               }
+               return new RawText(r.toString().getBytes(UTF_8));
        }
 }
index 4724677bb89007b90ee82ce97334cece3fac9480..f168e832846e7c02b87309ac1d21ea8042ebd212 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.diff;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -81,7 +82,7 @@ public class SimilarityIndexTest {
                                + "A\n" //
                                + "B\n" //
                                + "B\n" //
-                               + "B\n").getBytes("UTF-8");
+                               + "B\n").getBytes(UTF_8);
                SimilarityIndex si = new SimilarityIndex();
                si.hash(new ByteArrayInputStream(in), in.length, false);
                assertEquals(2, si.size());
@@ -129,12 +130,12 @@ public class SimilarityIndexTest {
                                + "D\r\n" //
                                + "B\r\n";
                SimilarityIndex src = new SimilarityIndex();
-               byte[] bytes1 = text.getBytes("UTF-8");
+               byte[] bytes1 = text.getBytes(UTF_8);
                src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true);
                src.sort();
 
                SimilarityIndex dst = new SimilarityIndex();
-               byte[] bytes2 = text.replace("\r", "").getBytes("UTF-8");
+               byte[] bytes2 = text.replace("\r", "").getBytes(UTF_8);
                dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true);
                dst.sort();
 
index 6ed2c215e95c6566cd2f803916d690d854af91d5..9afb58ecfbd37ab4040afda7718192e2aa82b359 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.gitrepo;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
@@ -54,7 +55,6 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.net.URI;
-import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -213,7 +213,8 @@ public class RepoCommandTest extends RepositoryTestCase {
                repos.put("platform/base", child);
 
                RevCommit commit = cmd
-                       .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
+                               .setInputStream(new ByteArrayInputStream(
+                                               xmlContent.toString().getBytes(UTF_8)))
                        .setRemoteReader(repos)
                        .setURI("platform/")
                        .setTargetURI("platform/superproject")
@@ -263,7 +264,7 @@ public class RepoCommandTest extends RepositoryTestCase {
                repos.put("plugins/cookbook", child);
 
                RevCommit commit = cmd
-                       .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
+                       .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
                        .setRemoteReader(repos)
                        .setURI("")
                        .setTargetURI("gerrit")
@@ -317,7 +318,7 @@ public class RepoCommandTest extends RepositoryTestCase {
                                repos.put(repoUrl, child);
 
                                RevCommit commit = cmd
-                                       .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
+                                       .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
                                        .setRemoteReader(repos)
                                        .setURI(baseUrl)
                                        .setTargetURI("gerrit")
index 4a7dcd535f9a35aa2a8d26df39ae0a9753b077a4..1178eb3e8a0f6a82db531230b709e4c0f8517d86 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.ignore;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.junit.Assert.assertEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -541,11 +542,11 @@ public class IgnoreNodeTest extends RepositoryTestCase {
                writeTrashFile(name, data.toString());
        }
 
-       private InputStream writeToString(String... rules) throws IOException {
+       private InputStream writeToString(String... rules) {
                StringBuilder data = new StringBuilder();
                for (String line : rules) {
                        data.append(line + "\n");
                }
-               return new ByteArrayInputStream(data.toString().getBytes("UTF-8"));
+               return new ByteArrayInputStream(data.toString().getBytes(UTF_8));
        }
 }
index 4228c9dbec53de7247319b06953c1f79ef639d43..3db27926c654e9a3f15268a28fb15ab900e538e4 100644 (file)
@@ -41,6 +41,7 @@
  */
 package org.eclipse.jgit.indexdiff;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -60,7 +61,6 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -130,8 +130,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase {
                File restoreScript = new File(testDir, name + ".sh");
                try (OutputStream out = new BufferedOutputStream(
                                new FileOutputStream(restoreScript));
-                               Writer writer = new OutputStreamWriter(out,
-                                               StandardCharsets.UTF_8)) {
+                               Writer writer = new OutputStreamWriter(out, UTF_8)) {
                        writer.write("echo `which git` 1>&2\n");
                        writer.write("echo `git --version` 1>&2\n");
                        writer.write("git init " + name + " && \\\n");
index 9d23d8334ce6a6be91be2589194292409ceda1b0..a3a435674dfcc1b541980c40b82a73352ab2faec 100644 (file)
@@ -46,6 +46,7 @@
 
 package org.eclipse.jgit.internal.storage.file;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -544,9 +545,9 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
        }
 
        @Test
-       public void test025_computeSha1NoStore() throws IOException {
+       public void test025_computeSha1NoStore() {
                byte[] data = "test025 some data, more than 16 bytes to get good coverage"
-                               .getBytes("ISO-8859-1");
+                               .getBytes(ISO_8859_1);
                try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
                        final ObjectId id = formatter.idFor(Constants.OBJ_BLOB, data);
                        assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());
index 7475d69f6cdf5ccc2f4860d4cf4fd48357f5d074..f1c62d4be25d03d6ded1b2822b1f2606facb9f1d 100644 (file)
@@ -45,6 +45,7 @@
 package org.eclipse.jgit.lib;
 
 import static java.lang.Integer.valueOf;
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.junit.JGitTestUtil.concat;
 import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
 import static org.eclipse.jgit.lib.Constants.OBJ_BAD;
@@ -68,7 +69,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 
-import java.io.UnsupportedEncodingException;
 import java.text.MessageFormat;
 
 import org.eclipse.jgit.errors.CorruptObjectException;
@@ -1450,11 +1450,11 @@ public class ObjectCheckerTest {
 
        @Test
        public void testInvalidTreeDuplicateNames5()
-                       throws UnsupportedEncodingException, CorruptObjectException {
+                       throws CorruptObjectException {
                StringBuilder b = new StringBuilder();
                entry(b, "100644 A");
                entry(b, "100644 a");
-               byte[] data = b.toString().getBytes("UTF-8");
+               byte[] data = b.toString().getBytes(UTF_8);
                checker.setSafeForWindows(true);
                assertCorrupt("duplicate entry names", OBJ_TREE, data);
                assertSkipListAccepts(OBJ_TREE, data);
@@ -1464,11 +1464,11 @@ public class ObjectCheckerTest {
 
        @Test
        public void testInvalidTreeDuplicateNames6()
-                       throws UnsupportedEncodingException, CorruptObjectException {
+                       throws CorruptObjectException {
                StringBuilder b = new StringBuilder();
                entry(b, "100644 A");
                entry(b, "100644 a");
-               byte[] data = b.toString().getBytes("UTF-8");
+               byte[] data = b.toString().getBytes(UTF_8);
                checker.setSafeForMacOS(true);
                assertCorrupt("duplicate entry names", OBJ_TREE, data);
                assertSkipListAccepts(OBJ_TREE, data);
@@ -1478,11 +1478,11 @@ public class ObjectCheckerTest {
 
        @Test
        public void testInvalidTreeDuplicateNames7()
-                       throws UnsupportedEncodingException, CorruptObjectException {
+                       throws CorruptObjectException {
                StringBuilder b = new StringBuilder();
                entry(b, "100644 \u0065\u0301");
                entry(b, "100644 \u00e9");
-               byte[] data = b.toString().getBytes("UTF-8");
+               byte[] data = b.toString().getBytes(UTF_8);
                checker.setSafeForMacOS(true);
                assertCorrupt("duplicate entry names", OBJ_TREE, data);
                assertSkipListAccepts(OBJ_TREE, data);
@@ -1492,11 +1492,11 @@ public class ObjectCheckerTest {
 
        @Test
        public void testInvalidTreeDuplicateNames8()
-                       throws UnsupportedEncodingException, CorruptObjectException {
+                       throws CorruptObjectException {
                StringBuilder b = new StringBuilder();
                entry(b, "100644 A");
                checker.setSafeForMacOS(true);
-               checker.checkTree(b.toString().getBytes("UTF-8"));
+               checker.checkTree(b.toString().getBytes(UTF_8));
        }
 
        @Test
index 77ecf19fbc205b7da5bd33e691ee6c38150231e8..3272d598bc6513243ab1c245612901960f214ee7 100644 (file)
@@ -52,7 +52,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
 import org.eclipse.jgit.api.Git;
@@ -714,7 +713,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
                }
                binary[50] = '\0';
 
-               writeTrashFile("file", new String(binary, StandardCharsets.UTF_8));
+               writeTrashFile("file", new String(binary, UTF_8));
                git.add().addFilepattern("file").call();
                RevCommit first = git.commit().setMessage("added file").call();
 
@@ -722,7 +721,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
                int idx = LINELEN * 1200 + 1;
                byte save = binary[idx];
                binary[idx] = '@';
-               writeTrashFile("file", new String(binary, StandardCharsets.UTF_8));
+               writeTrashFile("file", new String(binary, UTF_8));
 
                binary[idx] = save;
                git.add().addFilepattern("file").call();
@@ -731,7 +730,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
 
                git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call();
                binary[LINELEN * 1500 + 1] = '!';
-               writeTrashFile("file", new String(binary, StandardCharsets.UTF_8));
+               writeTrashFile("file", new String(binary, UTF_8));
                git.add().addFilepattern("file").call();
                RevCommit sideCommit = git.commit().setAll(true)
                        .setMessage("modified file l 1500").call();
index 1a158425c9ebe1241c3f531f349dbc2894791417..88f240bb1f39557548b86ec5ab253ff28d72398f 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.revwalk;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -113,7 +114,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
                assertNull(c.getTree());
                assertNull(c.parents);
 
-               c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
+               c.parseCanonical(rw, body.toString().getBytes(UTF_8));
                assertNotNull(c.getTree());
                assertEquals(treeId, c.getTree().getId());
                assertSame(rw.lookupTree(treeId), c.getTree());
@@ -147,7 +148,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
 
                final RevCommit c;
                c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
-               c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+               c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
                return c;
        }
 
@@ -160,7 +161,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
 
                final RevCommit c;
                c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
-               c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+               c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
 
                assertEquals("", c.getFullMessage());
                assertEquals("", c.getShortMessage());
@@ -175,7 +176,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
 
                final RevCommit c;
                c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
-               c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+               c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
 
                assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent());
                assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent());
@@ -184,13 +185,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
        @Test
        public void testParse_implicit_UTF8_encoded() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
-               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
-               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("UTF-8"));
-               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
                final RevCommit c;
                c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
                c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -204,13 +205,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
        @Test
        public void testParse_implicit_mixed_encoded() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
-               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
-               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("ISO-8859-1"));
-               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
+               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
                final RevCommit c;
                c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
                c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -259,14 +260,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
        @Test
        public void testParse_explicit_bad_encoded() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
-               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
-               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("ISO-8859-1"));
-               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
-               b.write("encoding EUC-JP\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Hi\n".getBytes("UTF-8"));
+               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
+               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+               b.write("encoding EUC-JP\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Hi\n".getBytes(UTF_8));
                final RevCommit c;
                c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
                c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -290,14 +291,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
        @Test
        public void testParse_explicit_bad_encoded2() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
-               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
-               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("UTF-8"));
-               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
-               b.write("encoding ISO-8859-1\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Hi\n".getBytes("UTF-8"));
+               b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+               b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+               b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+               b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Hi\n".getBytes(UTF_8));
                final RevCommit c;
                c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
                c.parseCanonical(new RevWalk(db), b.toByteArray());
index f97043b7e81b09eede7764586a015b4c2c325a3b..38bd371b909f83a76ee0126501b49831b2f6c0e8 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.revwalk;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -97,7 +98,7 @@ public class RevTagParseTest extends RepositoryTestCase {
                assertNull(c.getObject());
                assertNull(c.getTagName());
 
-               c.parseCanonical(rw, b.toString().getBytes("UTF-8"));
+               c.parseCanonical(rw, b.toString().getBytes(UTF_8));
                assertNotNull(c.getObject());
                assertEquals(id, c.getObject().getId());
                assertSame(rw.lookupAny(id, typeCode), c.getObject());
@@ -140,7 +141,7 @@ public class RevTagParseTest extends RepositoryTestCase {
                assertNull(c.getObject());
                assertNull(c.getTagName());
 
-               c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
+               c.parseCanonical(rw, body.toString().getBytes(UTF_8));
                assertNotNull(c.getObject());
                assertEquals(treeId, c.getObject().getId());
                assertSame(rw.lookupTree(treeId), c.getObject());
@@ -188,7 +189,7 @@ public class RevTagParseTest extends RepositoryTestCase {
                assertNull(c.getObject());
                assertNull(c.getTagName());
 
-               c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
+               c.parseCanonical(rw, body.toString().getBytes(UTF_8));
                assertNotNull(c.getObject());
                assertEquals(treeId, c.getObject().getId());
                assertSame(rw.lookupTree(treeId), c.getObject());
@@ -212,7 +213,7 @@ public class RevTagParseTest extends RepositoryTestCase {
 
                final RevTag c;
                c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
-               c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+               c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
                return c;
        }
 
@@ -220,17 +221,17 @@ public class RevTagParseTest extends RepositoryTestCase {
        public void testParse_implicit_UTF8_encoded() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
                b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
-                               .getBytes("UTF-8"));
-               b.write("type tree\n".getBytes("UTF-8"));
-               b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
+                               .getBytes(UTF_8));
+               b.write("type tree\n".getBytes(UTF_8));
+               b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
 
                b
                                .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
-                                               .getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+                                               .getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
                final RevTag c;
                c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
                c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -245,16 +246,15 @@ public class RevTagParseTest extends RepositoryTestCase {
        public void testParse_implicit_mixed_encoded() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
                b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
-                               .getBytes("UTF-8"));
-               b.write("type tree\n".getBytes("UTF-8"));
-               b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
-               b
-                               .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
-                                               .getBytes("ISO-8859-1"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+                               .getBytes(UTF_8));
+               b.write("type tree\n".getBytes(UTF_8));
+               b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+               b.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
+                               .getBytes(ISO_8859_1));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
                final RevTag c;
                c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
                c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -307,17 +307,17 @@ public class RevTagParseTest extends RepositoryTestCase {
        public void testParse_explicit_bad_encoded() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
                b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
-                               .getBytes("UTF-8"));
-               b.write("type tree\n".getBytes("UTF-8"));
-               b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
+                               .getBytes(UTF_8));
+               b.write("type tree\n".getBytes(UTF_8));
+               b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
                b
                                .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
-                                               .getBytes("ISO-8859-1"));
-               b.write("encoding EUC-JP\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Hi\n".getBytes("UTF-8"));
+                                               .getBytes(ISO_8859_1));
+               b.write("encoding EUC-JP\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Hi\n".getBytes(UTF_8));
                final RevTag c;
                c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
                c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -342,17 +342,17 @@ public class RevTagParseTest extends RepositoryTestCase {
        public void testParse_explicit_bad_encoded2() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
                b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
-                               .getBytes("UTF-8"));
-               b.write("type tree\n".getBytes("UTF-8"));
-               b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
+                               .getBytes(UTF_8));
+               b.write("type tree\n".getBytes(UTF_8));
+               b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
                b
                                .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
-                                               .getBytes("UTF-8"));
-               b.write("encoding ISO-8859-1\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
-               b.write("\n".getBytes("UTF-8"));
-               b.write("Hi\n".getBytes("UTF-8"));
+                                               .getBytes(UTF_8));
+               b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+               b.write("\n".getBytes(UTF_8));
+               b.write("Hi\n".getBytes(UTF_8));
                final RevTag c;
                c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
                c.parseCanonical(new RevWalk(db), b.toByteArray());
index eb7bc4f7e77e6977e4df90b6f259ed1ed79729c4..2a54dc614078a3723dccd1135b68aac94b47e2f2 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.storage.file;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.util.FileUtils.pathToString;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -104,7 +105,7 @@ public class FileBasedConfigTest {
 
        @Test
        public void testUTF8withoutBOM() throws IOException, ConfigInvalidException {
-               final File file = createFile(CONTENT1.getBytes("UTF-8"));
+               final File file = createFile(CONTENT1.getBytes(UTF_8));
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
                config.load();
                assertEquals(ALICE, config.getString(USER, null, NAME));
@@ -120,7 +121,7 @@ public class FileBasedConfigTest {
                bos1.write(0xEF);
                bos1.write(0xBB);
                bos1.write(0xBF);
-               bos1.write(CONTENT1.getBytes("UTF-8"));
+               bos1.write(CONTENT1.getBytes(UTF_8));
 
                final File file = createFile(bos1.toByteArray());
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -134,7 +135,7 @@ public class FileBasedConfigTest {
                bos2.write(0xEF);
                bos2.write(0xBB);
                bos2.write(0xBF);
-               bos2.write(CONTENT2.getBytes("UTF-8"));
+               bos2.write(CONTENT2.getBytes(UTF_8));
                assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
        }
 
index cc73c70c5892eca5f7b80f80872073e72d5ff656..a6f33451cea6be691db75be07d67ab91dc1d6381 100644 (file)
 
 package org.eclipse.jgit.util;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static org.eclipse.jgit.util.QuotedString.GIT_PATH;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertSame;
 
-import java.io.UnsupportedEncodingException;
-
 import org.eclipse.jgit.lib.Constants;
 import org.junit.Test;
 
@@ -63,12 +62,7 @@ public class QuotedStringGitPathStyleTest {
        }
 
        private static void assertDequote(final String exp, final String in) {
-               final byte[] b;
-               try {
-                       b = ('"' + in + '"').getBytes("ISO-8859-1");
-               } catch (UnsupportedEncodingException e) {
-                       throw new RuntimeException(e);
-               }
+               final byte[] b = ('"' + in + '"').getBytes(ISO_8859_1);
                final String r = GIT_PATH.dequote(b, 0, b.length);
                assertEquals(exp, r);
        }
index a8c576334ed8e43d5f653a457faadef4e65bc2d0..f1b3da293d9b2b320de76da30b158c2dd510c7f7 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.util;
 
+import static java.nio.charset.StandardCharsets.US_ASCII;
 import static org.eclipse.jgit.util.RawCharUtil.isWhitespace;
 import static org.eclipse.jgit.util.RawCharUtil.trimLeadingWhitespace;
 import static org.eclipse.jgit.util.RawCharUtil.trimTrailingWhitespace;
@@ -50,8 +51,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.io.UnsupportedEncodingException;
-
 import org.junit.Test;
 
 public class RawCharUtilTest {
@@ -78,37 +77,31 @@ public class RawCharUtilTest {
        /**
         * Test method for
         * {@link RawCharUtil#trimTrailingWhitespace(byte[], int, int)}.
-        *
-        * @throws UnsupportedEncodingException
         */
        @Test
-       public void testTrimTrailingWhitespace()
-                       throws UnsupportedEncodingException {
-               assertEquals(0, trimTrailingWhitespace("".getBytes("US-ASCII"), 0, 0));
-               assertEquals(0, trimTrailingWhitespace(" ".getBytes("US-ASCII"), 0, 1));
-               assertEquals(1, trimTrailingWhitespace("a ".getBytes("US-ASCII"), 0, 2));
-               assertEquals(2,
-                               trimTrailingWhitespace(" a ".getBytes("US-ASCII"), 0, 3));
-               assertEquals(3,
-                               trimTrailingWhitespace("  a".getBytes("US-ASCII"), 0, 3));
-               assertEquals(6, trimTrailingWhitespace(
-                               "  test   ".getBytes("US-ASCII"), 2, 9));
+       public void testTrimTrailingWhitespace() {
+               assertEquals(0, trimTrailingWhitespace("".getBytes(US_ASCII), 0, 0));
+               assertEquals(0, trimTrailingWhitespace(" ".getBytes(US_ASCII), 0, 1));
+               assertEquals(1, trimTrailingWhitespace("a ".getBytes(US_ASCII), 0, 2));
+               assertEquals(2, trimTrailingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
+               assertEquals(3, trimTrailingWhitespace("  a".getBytes(US_ASCII), 0, 3));
+               assertEquals(6,
+                               trimTrailingWhitespace("  test   ".getBytes(US_ASCII), 2, 9));
        }
 
        /**
         * Test method for
         * {@link RawCharUtil#trimLeadingWhitespace(byte[], int, int)}.
-        *
-        * @throws UnsupportedEncodingException
         */
        @Test
-       public void testTrimLeadingWhitespace() throws UnsupportedEncodingException {
-               assertEquals(0, trimLeadingWhitespace("".getBytes("US-ASCII"), 0, 0));
-               assertEquals(1, trimLeadingWhitespace(" ".getBytes("US-ASCII"), 0, 1));
-               assertEquals(0, trimLeadingWhitespace("a ".getBytes("US-ASCII"), 0, 2));
-               assertEquals(1, trimLeadingWhitespace(" a ".getBytes("US-ASCII"), 0, 3));
-               assertEquals(2, trimLeadingWhitespace("  a".getBytes("US-ASCII"), 0, 3));
-               assertEquals(2, trimLeadingWhitespace("  test   ".getBytes("US-ASCII"),
+       public void testTrimLeadingWhitespace() {
+               assertEquals(0, trimLeadingWhitespace("".getBytes(US_ASCII), 0, 0));
+               assertEquals(1, trimLeadingWhitespace(" ".getBytes(US_ASCII), 0, 1));
+               assertEquals(0, trimLeadingWhitespace("a ".getBytes(US_ASCII), 0, 2));
+               assertEquals(1, trimLeadingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
+               assertEquals(2, trimLeadingWhitespace("  a".getBytes(US_ASCII), 0, 3));
+               assertEquals(2,
+                               trimLeadingWhitespace("  test   ".getBytes(US_ASCII),
                                2, 9));
        }
 
index 6efdce6d779da521e3479925e1b5cb8872dfea23..02437986661a7f25e0a810f0a9f5259984d21e5f 100644 (file)
 
 package org.eclipse.jgit.util;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.io.UnsupportedEncodingException;
-
 import org.junit.Test;
 
 public class RawParseUtils_LineMapTest {
@@ -65,29 +64,29 @@ public class RawParseUtils_LineMapTest {
        }
 
        @Test
-       public void testTwoLineFooBar() throws UnsupportedEncodingException {
-               final byte[] buf = "foo\nbar\n".getBytes("ISO-8859-1");
+       public void testTwoLineFooBar() {
+               final byte[] buf = "foo\nbar\n".getBytes(ISO_8859_1);
                final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
                assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
        }
 
        @Test
-       public void testTwoLineNoLF() throws UnsupportedEncodingException {
-               final byte[] buf = "foo\nbar".getBytes("ISO-8859-1");
+       public void testTwoLineNoLF() {
+               final byte[] buf = "foo\nbar".getBytes(ISO_8859_1);
                final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
                assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
        }
 
        @Test
-       public void testBinary() throws UnsupportedEncodingException {
-               final byte[] buf = "xxxfoo\nb\0ar".getBytes("ISO-8859-1");
+       public void testBinary() {
+               final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1);
                final IntList map = RawParseUtils.lineMap(buf, 3, buf.length);
                assertArrayEquals(new int[]{Integer.MIN_VALUE, 3, buf.length}, asInts(map));
        }
 
        @Test
-       public void testFourLineBlanks() throws UnsupportedEncodingException {
-               final byte[] buf = "foo\n\n\nbar\n".getBytes("ISO-8859-1");
+       public void testFourLineBlanks() {
+               final byte[] buf = "foo\n\n\nbar\n".getBytes(ISO_8859_1);
                final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
 
                assertArrayEquals(new int[]{
index 194fab47fc22869f3c0ffd6d737011e6108081dc..e8566d243825ec8a7bc24482a7a3f5e249a98be7 100644 (file)
  */
 package org.eclipse.jgit.util;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.io.UnsupportedEncodingException;
-
 import org.eclipse.jgit.junit.RepositoryTestCase;
 import org.junit.Test;
 
@@ -94,11 +93,7 @@ public class RawSubStringPatternTest extends RepositoryTestCase {
        }
 
        private static RawCharSequence raw(String text) {
-               try {
-                       byte[] bytes = text.getBytes("UTF-8");
-                       return new RawCharSequence(bytes, 0, bytes.length);
-               } catch (UnsupportedEncodingException e) {
-                       throw new RuntimeException(e);
-               }
+               byte[] bytes = text.getBytes(UTF_8);
+               return new RawCharSequence(bytes, 0, bytes.length);
        }
 }
index 40cac93f3b3a87cd891c289cd4c9ab815ef4f5b3..38199d8aaf628a547cbc8bd5a27ac7f80f0acdf1 100644 (file)
 
 package org.eclipse.jgit.util.io;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
 
 import org.junit.Test;
 
@@ -129,10 +129,6 @@ public class AutoLFInputStreamTest {
        }
 
        private static byte[] asBytes(String in) {
-               try {
-                       return in.getBytes("UTF-8");
-               } catch (UnsupportedEncodingException ex) {
-                       throw new AssertionError();
-               }
+               return in.getBytes(UTF_8);
        }
 }
index 07789898a4c3ec8fc97eac47ecc7298b81371b77..e6045a91bd256f6471f436d89623429e59ce39fe 100644 (file)
@@ -43,6 +43,7 @@
 
 package org.eclipse.jgit.util.sha1;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -51,7 +52,6 @@ import static org.junit.Assume.assumeTrue;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
@@ -95,15 +95,15 @@ public class SHA1Test {
                                .fromString("a9993e364706816aba3e25717850c26c9cd0d89d");
 
                MessageDigest m = MessageDigest.getInstance("SHA-1");
-               m.update(TEST1.getBytes(StandardCharsets.UTF_8));
+               m.update(TEST1.getBytes(UTF_8));
                ObjectId m1 = ObjectId.fromRaw(m.digest());
 
                SHA1 s = SHA1.newInstance();
-               s.update(TEST1.getBytes(StandardCharsets.UTF_8));
+               s.update(TEST1.getBytes(UTF_8));
                ObjectId s1 = ObjectId.fromRaw(s.digest());
 
                s.reset();
-               s.update(TEST1.getBytes(StandardCharsets.UTF_8));
+               s.update(TEST1.getBytes(UTF_8));
                ObjectId s2 = s.toObjectId();
 
                assertEquals(m1, s1);
@@ -117,15 +117,15 @@ public class SHA1Test {
                                .fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1");
 
                MessageDigest m = MessageDigest.getInstance("SHA-1");
-               m.update(TEST2.getBytes(StandardCharsets.UTF_8));
+               m.update(TEST2.getBytes(UTF_8));
                ObjectId m1 = ObjectId.fromRaw(m.digest());
 
                SHA1 s = SHA1.newInstance();
-               s.update(TEST2.getBytes(StandardCharsets.UTF_8));
+               s.update(TEST2.getBytes(UTF_8));
                ObjectId s1 = ObjectId.fromRaw(s.digest());
 
                s.reset();
-               s.update(TEST2.getBytes(StandardCharsets.UTF_8));
+               s.update(TEST2.getBytes(UTF_8));
                ObjectId s2 = s.toObjectId();
 
                assertEquals(m1, s1);
index 64cb4ddba81b3e0b04f668463aee1855a3e721eb..13f91676ade091f280b53c5d0de77f90a9149655 100644 (file)
@@ -43,6 +43,8 @@
 
 package org.eclipse.jgit.transport;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -642,7 +644,7 @@ public class AmazonS3 {
                try {
                        final Mac m = Mac.getInstance(HMAC);
                        m.init(privateKey);
-                       sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes("UTF-8"))); //$NON-NLS-1$
+                       sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(UTF_8)));
                } catch (NoSuchAlgorithmException e) {
                        throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage()));
                } catch (InvalidKeyException e) {
index d43be8974c590776ebfe8e06c01b4048f09dec5c..7de4d2de1b44b219219e35a1a554019cdc31d643 100644 (file)
  */
 package org.eclipse.jgit.transport;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.io.File;
-import java.io.UnsupportedEncodingException;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 
@@ -69,7 +71,7 @@ public class HMACSHA1NonceGenerator implements NonceGenerator {
         */
        public HMACSHA1NonceGenerator(String seed) throws IllegalStateException {
                try {
-                       byte[] keyBytes = seed.getBytes("ISO-8859-1"); //$NON-NLS-1$
+                       byte[] keyBytes = seed.getBytes(ISO_8859_1);
                        SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1"); //$NON-NLS-1$
                        mac = Mac.getInstance("HmacSHA1"); //$NON-NLS-1$
                        mac.init(signingKey);
@@ -77,8 +79,6 @@ public class HMACSHA1NonceGenerator implements NonceGenerator {
                        throw new IllegalStateException(e);
                } catch (NoSuchAlgorithmException e) {
                        throw new IllegalStateException(e);
-               } catch (UnsupportedEncodingException e) {
-                       throw new IllegalStateException(e);
                }
        }
 
@@ -98,12 +98,7 @@ public class HMACSHA1NonceGenerator implements NonceGenerator {
                }
 
                String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$
-               byte[] rawHmac;
-               try {
-                       rawHmac = mac.doFinal(input.getBytes("UTF-8")); //$NON-NLS-1$
-               } catch (UnsupportedEncodingException e) {
-                       throw new IllegalStateException(e);
-               }
+               byte[] rawHmac = mac.doFinal(input.getBytes(UTF_8));
                return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$
        }
 
index c97daa958f5d9bcabbf70126394f421840d2eae8..bbc964227f50f63dfea75d6cee276dddb02ddbaa 100644 (file)
 
 package org.eclipse.jgit.transport;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION;
 import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -309,7 +309,7 @@ abstract class HttpAuthMethod {
                @Override
                void configureRequest(final HttpConnection conn) throws IOException {
                        String ident = user + ":" + pass; //$NON-NLS-1$
-                       String enc = Base64.encodeBytes(ident.getBytes("UTF-8")); //$NON-NLS-1$
+                       String enc = Base64.encodeBytes(ident.getBytes(UTF_8));
                        conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName()
                                        + " " + enc); //$NON-NLS-1$
                }
@@ -423,25 +423,17 @@ abstract class HttpAuthMethod {
                }
 
                private static String H(String data) {
-                       try {
-                               MessageDigest md = newMD5();
-                               md.update(data.getBytes("UTF-8")); //$NON-NLS-1$
-                               return LHEX(md.digest());
-                       } catch (UnsupportedEncodingException e) {
-                               throw new RuntimeException("UTF-8 encoding not available", e); //$NON-NLS-1$
-                       }
+                       MessageDigest md = newMD5();
+                       md.update(data.getBytes(UTF_8));
+                       return LHEX(md.digest());
                }
 
                private static String KD(String secret, String data) {
-                       try {
-                               MessageDigest md = newMD5();
-                               md.update(secret.getBytes("UTF-8")); //$NON-NLS-1$
-                               md.update((byte) ':');
-                               md.update(data.getBytes("UTF-8")); //$NON-NLS-1$
-                               return LHEX(md.digest());
-                       } catch (UnsupportedEncodingException e) {
-                               throw new RuntimeException("UTF-8 encoding not available", e); //$NON-NLS-1$
-                       }
+                       MessageDigest md = newMD5();
+                       md.update(secret.getBytes(UTF_8));
+                       md.update((byte) ':');
+                       md.update(data.getBytes(UTF_8));
+                       return LHEX(md.digest());
                }
 
                private static MessageDigest newMD5() {
index c05570b85164b5e3d77feca8f88e6948be2953d9..7f897982c2b666e993856942a4c4e2a32b75babb 100644 (file)
@@ -6,7 +6,8 @@
 
 package org.eclipse.jgit.util;
 
-import java.io.UnsupportedEncodingException;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.nio.charset.StandardCharsets;
 import java.text.MessageFormat;
 import java.util.Arrays;
@@ -40,9 +41,6 @@ public class Base64 {
        /** Indicates an invalid byte during decoding. */
        private final static byte INVALID_DEC = -3;
 
-       /** Preferred encoding. */
-       private final static String UTF_8 = "UTF-8"; //$NON-NLS-1$
-
        /** The 64 valid Base64 values. */
        private final static byte[] ENC;
 
@@ -54,15 +52,11 @@ public class Base64 {
        private final static byte[] DEC;
 
        static {
-               try {
-                       ENC = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" // //$NON-NLS-1$
-                                       + "abcdefghijklmnopqrstuvwxyz" // //$NON-NLS-1$
-                                       + "0123456789" // //$NON-NLS-1$
-                                       + "+/" // //$NON-NLS-1$
-                       ).getBytes(UTF_8);
-               } catch (UnsupportedEncodingException uee) {
-                       throw new RuntimeException(uee.getMessage(), uee);
-               }
+               ENC = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" // //$NON-NLS-1$
+                               + "abcdefghijklmnopqrstuvwxyz" // //$NON-NLS-1$
+                               + "0123456789" // //$NON-NLS-1$
+                               + "+/" // //$NON-NLS-1$
+               ).getBytes(UTF_8);
 
                DEC = new byte[128];
                Arrays.fill(DEC, INVALID_DEC);
@@ -301,7 +295,7 @@ public class Base64 {
         * @return the decoded data
         */
        public static byte[] decode(String s) {
-               byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
+               byte[] bytes = s.getBytes(UTF_8);
                return decode(bytes, 0, bytes.length);
        }
 }