From f07b60239c3e3bca7c75705c678dd32a12047e09 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 8 Mar 2018 09:44:01 +0900 Subject: [PATCH] Consistently use Constants.CHARSET rather than StandardCharsets.UTF_8 Change-Id: I6714fc3666e1bced22abba94ceb700477349586e Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/archive/TarFormat.java | 7 +- .../http/test/SmartClientSmartServerTest.java | 4 +- .../org/eclipse/jgit/junit/JGitTestUtil.java | 6 +- .../junit/LocalDiskRepositoryTestCase.java | 4 +- .../jgit/junit/RepositoryTestCase.java | 4 +- .../eclipse/jgit/junit/TestRepository.java | 4 +- .../jgit/lfs/server/fs/LfsServerTest.java | 6 +- .../META-INF/MANIFEST.MF | 1 + .../jgit/lfs/server/LfsProtocolServlet.java | 6 +- .../eclipse/jgit/lfs/server/s3/SignerV4.java | 8 +- .../jgit/lfs/test/LongObjectIdTestUtils.java | 4 +- .../eclipse/jgit/lfs/lib/LFSPointerTest.java | 4 +- .../src/org/eclipse/jgit/lfs/LfsPointer.java | 8 +- .../org/eclipse/jgit/lfs/LfsPrePushHook.java | 4 +- .../org/eclipse/jgit/lfs/SmudgeFilter.java | 5 +- .../tst/org/eclipse/jgit/pgm/ArchiveTest.java | 6 +- .../org/eclipse/jgit/pgm/CommandCatalog.java | 4 +- .../src/org/eclipse/jgit/pgm/Main.java | 4 +- .../jgit/pgm/debug/BenchmarkReftable.java | 4 +- .../eclipse/jgit/pgm/debug/WriteReftable.java | 6 +- .../CGitVsJGitRandomIgnorePatternTest.java | 6 +- .../jgit/api/EolStreamTypeUtilTest.java | 10 +- .../eclipse/jgit/api/NotesCommandTest.java | 4 +- .../org/eclipse/jgit/api/PullCommandTest.java | 6 +- .../jgit/api/PullCommandWithRebaseTest.java | 6 +- .../eclipse/jgit/api/RebaseCommandTest.java | 8 +- .../jgit/diff/AbstractDiffTestCase.java | 4 +- .../org/eclipse/jgit/diff/RawTextTest.java | 24 ++--- .../jgit/diff/SimilarityIndexTest.java | 8 +- .../DirCacheCGitCompatabilityTest.java | 6 +- .../jgit/gitrepo/ManifestParserTest.java | 6 +- .../eclipse/jgit/gitrepo/RepoCommandTest.java | 16 +-- .../eclipse/jgit/ignore/IgnoreNodeTest.java | 4 +- .../indexdiff/IndexDiffWithSymlinkTest.java | 4 +- .../internal/storage/file/RefUpdateTest.java | 4 +- .../storage/file/T0003_BasicTest.java | 4 +- .../jgit/junit/TestRepositoryTest.java | 4 +- .../eclipse/jgit/lib/ObjectCheckerTest.java | 10 +- .../eclipse/jgit/merge/ResolveMergerTest.java | 14 +-- .../org/eclipse/jgit/patch/GetTextTest.java | 6 +- .../jgit/revwalk/RevCommitParseTest.java | 102 +++++++++--------- .../eclipse/jgit/revwalk/RevTagParseTest.java | 102 +++++++++--------- .../storage/file/FileBasedConfigTest.java | 8 +- .../jgit/transport/BundleWriterTest.java | 4 +- .../jgit/transport/WalkEncryptionTest.java | 8 +- .../jgit/util/RawSubStringPatternTest.java | 4 +- .../jgit/util/io/AutoLFInputStreamTest.java | 4 +- .../org/eclipse/jgit/util/sha1/SHA1Test.java | 14 +-- .../src/org/eclipse/jgit/hooks/GitHook.java | 6 +- .../internal/storage/dfs/DfsStreamKey.java | 4 +- .../jgit/internal/storage/file/GcLog.java | 4 +- .../storage/file/LazyObjectIdSetFile.java | 4 +- .../storage/reftable/BlockReader.java | 8 +- .../storage/reftable/BlockWriter.java | 12 +-- .../reftable/ReftableOutputStream.java | 4 +- .../storage/reftable/ReftableReader.java | 6 +- .../org/eclipse/jgit/lib/BlobBasedConfig.java | 5 +- .../src/org/eclipse/jgit/lib/Config.java | 5 +- .../src/org/eclipse/jgit/lib/Constants.java | 6 +- .../org/eclipse/jgit/lib/RebaseTodoFile.java | 6 +- .../eclipse/jgit/lib/TextProgressMonitor.java | 4 +- .../org/eclipse/jgit/revwalk/RevCommit.java | 4 +- .../src/org/eclipse/jgit/revwalk/RevTag.java | 6 +- .../jgit/storage/file/FileBasedConfig.java | 6 +- .../org/eclipse/jgit/transport/AmazonS3.java | 4 +- .../transport/HMACSHA1NonceGenerator.java | 4 +- .../jgit/transport/HttpAuthMethod.java | 10 +- .../jgit/transport/ProgressSpinner.java | 4 +- .../jgit/transport/PushCertificateIdent.java | 6 +- .../jgit/transport/PushCertificateStore.java | 6 +- .../eclipse/jgit/transport/RefAdvertiser.java | 4 +- .../org/eclipse/jgit/transport/Transport.java | 3 +- .../src/org/eclipse/jgit/util/Base64.java | 9 +- .../eclipse/jgit/util/FS_Win32_Cygwin.java | 4 +- .../org/eclipse/jgit/util/HttpSupport.java | 4 +- 75 files changed, 331 insertions(+), 316 deletions(-) diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java index 9379f022e..9ed60d941 100644 --- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java +++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java @@ -42,6 +42,8 @@ */ package org.eclipse.jgit.archive; +import static org.eclipse.jgit.lib.Constants.CHARACTER_ENCODING; + import java.io.IOException; import java.io.OutputStream; import java.text.MessageFormat; @@ -82,7 +84,8 @@ public final class TarFormat extends BaseFormat implements @Override public ArchiveOutputStream createArchiveOutputStream(OutputStream s, Map o) throws IOException { - TarArchiveOutputStream out = new TarArchiveOutputStream(s, "UTF-8"); //$NON-NLS-1$ + TarArchiveOutputStream out = new TarArchiveOutputStream(s, + CHARACTER_ENCODING); out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX); return applyFormatOptions(out, o); @@ -97,7 +100,7 @@ public final class TarFormat extends BaseFormat implements final TarArchiveEntry entry = new TarArchiveEntry( path, TarConstants.LF_SYMLINK); entry.setLinkName(new String( - loader.getCachedBytes(100), "UTF-8")); //$NON-NLS-1$ + loader.getCachedBytes(100), CHARACTER_ENCODING)); out.putArchiveEntry(entry); out.closeArchiveEntry(); return; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java index 5f40be4e0..6ded21f8c 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.http.test; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; 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; @@ -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(UTF_8)); + "testInvalidWant".getBytes(CHARSET)); Repository dst = createBareRepository(); try (Transport t = Transport.open(dst, remoteURI); diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java index cef81a062..27f745e4e 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.File; import java.io.FileNotFoundException; @@ -246,7 +246,7 @@ public abstract class JGitTestUtil { throws IOException { FileUtils.mkdirs(f.getParentFile(), true); try (Writer w = new OutputStreamWriter(new FileOutputStream(f), - UTF_8)) { + CHARSET)) { w.write(body); } } @@ -263,7 +263,7 @@ public abstract class JGitTestUtil { */ public static String read(final File file) throws IOException { final byte[] body = IO.readFully(file); - return new String(body, 0, body.length, UTF_8); + return new String(body, 0, body.length, CHARSET); } /** diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index 568bc3b0e..3c00bd3df 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; @@ -352,7 +352,7 @@ public abstract class LocalDiskRepositoryTestCase { if (0 != (includedOptions & CONTENT)) { sb.append(", content:" + new String(repo.open(entry.getObjectId(), - Constants.OBJ_BLOB).getCachedBytes(), UTF_8)); + Constants.OBJ_BLOB).getCachedBytes(), CHARSET)); } if (0 != (includedOptions & ASSUME_UNCHANGED)) sb.append(", assume-unchanged:" diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java index afc2c445c..5a83a1f49 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java @@ -46,7 +46,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import java.io.File; @@ -199,7 +199,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { protected static void checkFile(File f, final String checkData) throws IOException { try (Reader r = new InputStreamReader(new FileInputStream(f), - UTF_8)) { + CHARSET)) { if (checkData.length() > 0) { char[] data = new char[checkData.length()]; assertEquals(data.length, r.read(data)); diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 41634e7cd..89a86d8ee 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -268,7 +268,7 @@ public class TestRepository { * @throws Exception */ public RevBlob blob(final String content) throws Exception { - return blob(content.getBytes(UTF_8)); + return blob(content.getBytes(CHARSET)); } /** diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java index 10823b878..50a06f94d 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.lfs.server.fs; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import java.io.BufferedInputStream; @@ -211,11 +211,11 @@ public abstract class LfsServerTest { if (buf.hasArray()) { error = new String(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), - UTF_8); + CHARSET); } else { final byte[] b = new byte[buf.remaining()]; buf.duplicate().get(b); - error = new String(b, UTF_8); + error = new String(b, CHARSET); } } catch (IOException e) { error = statusLine.getReasonPhrase(); diff --git a/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF index 690abb27e..28b123165 100644 --- a/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF @@ -31,6 +31,7 @@ Import-Package: com.google.gson;version="[2.8.0,3.0.0)", org.eclipse.jgit.lfs.errors;version="[5.0.0,5.1.0)", org.eclipse.jgit.lfs.internal;version="[5.0.0,5.1.0)", org.eclipse.jgit.lfs.lib;version="[5.0.0,5.1.0)", + org.eclipse.jgit.lib;version="[5.0.0,5.1.0)", org.eclipse.jgit.nls;version="[5.0.0,5.1.0)", org.eclipse.jgit.transport.http;version="[5.0.0,5.1.0)", org.eclipse.jgit.transport.http.apache;version="[5.0.0,5.1.0)", diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java index c7f55dd3c..d22d45967 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.lfs.server; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.apache.http.HttpStatus.SC_FORBIDDEN; import static org.apache.http.HttpStatus.SC_INSUFFICIENT_STORAGE; import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR; @@ -202,10 +202,10 @@ public abstract class LfsProtocolServlet extends HttpServlet { protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Writer w = new BufferedWriter( - new OutputStreamWriter(res.getOutputStream(), UTF_8)); + new OutputStreamWriter(res.getOutputStream(), CHARSET)); Reader r = new BufferedReader( - new InputStreamReader(req.getInputStream(), UTF_8)); + new InputStreamReader(req.getInputStream(), CHARSET)); LfsRequest request = LfsGson.fromJson(r, LfsRequest.class); String path = req.getPathInfo(); diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java index b21c94e4e..374a56058 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java @@ -43,7 +43,7 @@ */ package org.eclipse.jgit.lfs.server.s3; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; import java.io.UnsupportedEncodingException; @@ -359,13 +359,13 @@ class SignerV4 { private static byte[] hash(String s) { MessageDigest md = Constants.newMessageDigest(); - md.update(s.getBytes(UTF_8)); + md.update(s.getBytes(CHARSET)); return md.digest(); } private static byte[] sign(String stringData, byte[] key) { try { - byte[] data = stringData.getBytes(UTF_8); + byte[] data = stringData.getBytes(CHARSET); 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, UTF_8.name()); + encoded = URLEncoder.encode(url, CHARSET.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e); } diff --git a/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java b/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java index c3c385946..e3c6ef80b 100644 --- a/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java +++ b/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.lfs.test; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedInputStream; import java.io.FileNotFoundException; @@ -66,7 +66,7 @@ public class LongObjectIdTestUtils { */ public static LongObjectId hash(String s) { MessageDigest md = Constants.newMessageDigest(); - md.update(s.getBytes(UTF_8)); + md.update(s.getBytes(CHARSET)); return LongObjectId.fromRaw(md.digest()); } diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java index 146a25ed3..a1283ddf4 100644 --- a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java +++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.lfs.lib; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARACTER_ENCODING; import static org.junit.Assert.assertEquals; import java.io.ByteArrayOutputStream; @@ -66,7 +66,7 @@ public class LFSPointerTest { assertEquals( "version https://git-lfs.github.com/spec/v1\noid sha256:" + s + "\nsize 4\n", - baos.toString(UTF_8.name())); + baos.toString(CHARACTER_ENCODING)); } } } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java index 0e3830c09..4f959409f 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.lfs; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedReader; import java.io.IOException; @@ -134,7 +134,7 @@ public class LfsPointer implements Comparable { */ public void encode(OutputStream out) { try (PrintStream ps = new PrintStream(out, false, - UTF_8.name())) { + CHARSET.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$ @@ -143,7 +143,7 @@ public class LfsPointer implements Comparable { ps.print(size + "\n"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { // should not happen, we are using a standard charset - throw new UnsupportedCharsetException(UTF_8.name()); + throw new UnsupportedCharsetException(CHARSET.name()); } } @@ -165,7 +165,7 @@ public class LfsPointer implements Comparable { long sz = -1; try (BufferedReader br = new BufferedReader( - new InputStreamReader(in, UTF_8))) { + new InputStreamReader(in, CHARSET))) { for (String s = br.readLine(); s != null; s = br.readLine()) { if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$ continue; diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java index c522572ee..7fd7c216a 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.lfs; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lfs.Protocol.OPERATION_UPLOAD; import static org.eclipse.jgit.lfs.internal.LfsConnectionFactory.toRequest; import static org.eclipse.jgit.transport.http.HttpConnection.HTTP_OK; @@ -204,7 +204,7 @@ public class LfsPrePushHook extends PrePushHook { } Gson gson = Protocol.gson(); api.getOutputStream().write( - gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(UTF_8)); + gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(CHARSET)); int responseCode = api.getResponseCode(); if (responseCode != HTTP_OK) { throw new IOException( diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java index e2ab30923..6bff12f9c 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java @@ -42,11 +42,12 @@ */ package org.eclipse.jgit.lfs; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.text.MessageFormat; @@ -169,7 +170,7 @@ public class SmudgeFilter extends FilterCommand { .write(gson .toJson(LfsConnectionFactory .toRequest(Protocol.OPERATION_DOWNLOAD, res)) - .getBytes(StandardCharsets.UTF_8)); + .getBytes(CHARSET)); int responseCode = lfsServerConn.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK) { throw new IOException( diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java index e5c85ebfc..e992ddfb5 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.pgm; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -612,7 +612,7 @@ public class ArchiveTest extends CLIRepositoryTestCase { private BufferedReader readFromProcess(Process proc) throws Exception { return new BufferedReader( - new InputStreamReader(proc.getInputStream(), UTF_8)); + new InputStreamReader(proc.getInputStream(), CHARSET)); } private void grepForEntry(String name, String mode, String... cmdline) @@ -750,7 +750,7 @@ public class ArchiveTest extends CLIRepositoryTestCase { // found! List l = new ArrayList<>(); BufferedReader reader = new BufferedReader( - new InputStreamReader(in, UTF_8)); + new InputStreamReader(in, CHARSET)); String line; while ((line = reader.readLine()) != null) l.add(line); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java index 81aeef8cd..0bc80f7d3 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.pgm; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedReader; import java.io.IOException; @@ -151,7 +151,7 @@ public class CommandCatalog { final BufferedReader cIn; try { final InputStream in = cUrl.openStream(); - cIn = new BufferedReader(new InputStreamReader(in, UTF_8)); + cIn = new BufferedReader(new InputStreamReader(in, CHARSET)); } catch (IOException err) { // If we cannot read from the service list, go to the next. // diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index a376bc098..75612be75 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.pgm; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.File; import java.io.IOException; @@ -217,7 +217,7 @@ public class Main { } PrintWriter createErrorWriter() { - return new PrintWriter(new OutputStreamWriter(System.err, UTF_8)); + return new PrintWriter(new OutputStreamWriter(System.err, CHARSET)); } private void execute(final String[] argv) throws Exception { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java index 248eaac8a..575a12215 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.pgm.debug; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.lib.Constants.MASTER; import static org.eclipse.jgit.lib.Constants.R_HEADS; @@ -154,7 +154,7 @@ class BenchmarkReftable extends TextBuiltin { throws IOException, FileNotFoundException { RefList.Builder list = new RefList.Builder<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(lsRemotePath), UTF_8))) { + new FileInputStream(lsRemotePath), CHARSET))) { Ref last = null; String line; while ((line = br.readLine()) != null) { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java index 6cbc1b082..c5ea028be 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.pgm.debug; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.lib.Constants.MASTER; import static org.eclipse.jgit.lib.Constants.R_HEADS; @@ -192,7 +192,7 @@ class WriteReftable extends TextBuiltin { static List readRefs(String inputFile) throws IOException { List refs = new ArrayList<>(); try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(inputFile), UTF_8))) { + new InputStreamReader(new FileInputStream(inputFile), CHARSET))) { String line; while ((line = br.readLine()) != null) { ObjectId id = ObjectId.fromString(line.substring(0, 40)); @@ -227,7 +227,7 @@ class WriteReftable extends TextBuiltin { List log = new ArrayList<>(); try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(logPath), UTF_8))) { + new InputStreamReader(new FileInputStream(logPath), CHARSET))) { @SuppressWarnings("nls") Pattern pattern = Pattern.compile("([^,]+)" // 1: ref + ",([0-9]+(?:[.][0-9]+)?)" // 2: time 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 438d2d625..4d9e86422 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,7 +42,7 @@ */ package org.eclipse.jgit.ignore; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedReader; import java.io.File; @@ -158,7 +158,7 @@ public class CGitVsJGitRandomIgnorePatternTest { this.gitDir = gitDir; this.pattern = pattern; Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")), - (pattern + "\n").getBytes(UTF_8), StandardOpenOption.CREATE, + (pattern + "\n").getBytes(CHARSET), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE); } @@ -188,7 +188,7 @@ public class CGitVsJGitRandomIgnorePatternTest { Process proc = Runtime.getRuntime().exec(command, new String[0], gitDir); try (OutputStream out = proc.getOutputStream()) { - out.write((path + "\n").getBytes(UTF_8)); + out.write((path + "\n").getBytes(CHARSET)); out.flush(); } return proc; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java index 1e3a39aad..bb303cc41 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java @@ -42,7 +42,7 @@ package org.eclipse.jgit.api; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; 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; @@ -150,8 +150,8 @@ public class EolStreamTypeUtilTest { EolStreamType streamTypeWithBinaryCheck, String output, String expectedConversion) throws Exception { ByteArrayOutputStream b; - byte[] outputBytes = output.getBytes(UTF_8); - byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8); + byte[] outputBytes = output.getBytes(CHARSET); + byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET); // test using output text and assuming it was declared TEXT b = new ByteArrayOutputStream(); @@ -277,8 +277,8 @@ public class EolStreamTypeUtilTest { private void testCheckin(EolStreamType streamTypeText, EolStreamType streamTypeWithBinaryCheck, String input, String expectedConversion) throws Exception { - byte[] inputBytes = input.getBytes(UTF_8); - byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8); + byte[] inputBytes = input.getBytes(CHARSET); + byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET); // test using input text and assuming it was declared TEXT try (InputStream in = EolStreamTypeUtil.wrapInputStream( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java index 6e06e9545..e234aa339 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.api; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import java.util.List; @@ -88,7 +88,7 @@ public class NotesCommandTest extends RepositoryTestCase { git.notesAdd().setObjectId(commit2).setMessage("data").call(); Note note = git.notesShow().setObjectId(commit2).call(); String content = new String(db.open(note.getData()).getCachedBytes(), - UTF_8); + CHARSET); assertEquals(content, "data"); git.notesRemove().setObjectId(commit2).call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java index 9461c4250..0b0e3bf3e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.api; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -592,7 +592,7 @@ public class PullCommandTest extends RepositoryTestCase { private static void writeToFile(File actFile, String string) throws IOException { try (FileOutputStream fos = new FileOutputStream(actFile)) { - fos.write(string.getBytes(UTF_8)); + fos.write(string.getBytes(CHARSET)); } } @@ -606,7 +606,7 @@ public class PullCommandTest extends RepositoryTestCase { bos.write(buffer, 0, read); read = fis.read(buffer); } - String content = new String(bos.toByteArray(), UTF_8); + String content = new String(bos.toByteArray(), CHARSET); assertEquals(string, content); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java index 913b4ac43..b349c66ca 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.api; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -396,7 +396,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase { private static void writeToFile(File actFile, String string) throws IOException { try (FileOutputStream fos = new FileOutputStream(actFile)) { - fos.write(string.getBytes(UTF_8)); + fos.write(string.getBytes(CHARSET)); } } @@ -410,7 +410,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase { bos.write(buffer, 0, read); read = fis.read(buffer); } - String content = new String(bos.toByteArray(), UTF_8); + String content = new String(bos.toByteArray(), CHARSET); assertEquals(string, content); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java index 2bf91aeed..96e7091ae 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.api; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; @@ -1464,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(CHARSET)); assertEquals(ident.getName(), parsedIdent.getName()); assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); // this is rounded to the last second @@ -1481,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(CHARSET)); assertEquals(ident.getName(), parsedIdent.getName()); assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); assertEquals(123456789000L, parsedIdent.getWhen().getTime()); @@ -2104,7 +2104,7 @@ public class RebaseCommandTest extends RepositoryTestCase { int count = 0; File todoFile = getTodoFile(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(todoFile), UTF_8))) { + new FileInputStream(todoFile), CHARSET))) { String line = br.readLine(); while (line != null) { int firstBlank = line.indexOf(' '); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java index 0f13a68b2..32f34213e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.diff; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -240,6 +240,6 @@ public abstract class AbstractDiffTestCase { r.append(text.charAt(i)); r.append('\n'); } - return new RawText(r.toString().getBytes(UTF_8)); + return new RawText(r.toString().getBytes(CHARSET)); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java index 6ad59b9e5..69e40777c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.diff; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -136,8 +136,8 @@ 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(CHARSET)); + RawText b = new RawText("p\na b \nR\n c d \n".getBytes(CHARSET)); e = new Edit(0, 4, 0, 4); e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(2, 3, 2, 3), e); @@ -149,14 +149,14 @@ public class RawTextTest { 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(CHARSET)); + b = new RawText("S\n\n y\n".getBytes(CHARSET)); 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(CHARSET)); + b = new RawText("R\n y\n".getBytes(CHARSET)); e = new Edit(0, 3, 0, 2); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(0, 2, 0, 1), e); @@ -167,8 +167,8 @@ public class RawTextTest { 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(CHARSET)); + b = new RawText("start of line".getBytes(CHARSET)); e = new Edit(0, 1, 0, 1); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(0, 1, 0, 1), e); @@ -179,8 +179,8 @@ public class RawTextTest { 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(CHARSET)); + b = new RawText("start of\nlastline".getBytes(CHARSET)); e = new Edit(0, 1, 0, 2); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(0, 1, 0, 2), e); @@ -239,6 +239,6 @@ public class RawTextTest { r.append(text.charAt(i)); r.append('\n'); } - return new RawText(r.toString().getBytes(UTF_8)); + return new RawText(r.toString().getBytes(CHARSET)); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java index f168e8328..51a6f8121 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.diff; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -82,7 +82,7 @@ public class SimilarityIndexTest { + "A\n" // + "B\n" // + "B\n" // - + "B\n").getBytes(UTF_8); + + "B\n").getBytes(CHARSET); SimilarityIndex si = new SimilarityIndex(); si.hash(new ByteArrayInputStream(in), in.length, false); assertEquals(2, si.size()); @@ -130,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(CHARSET); 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(CHARSET); dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true); dst.sort(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java index dec17623f..80d432985 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.dircache; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.junit.Assert.assertEquals; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -236,7 +236,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { private static Map readLsFiles() throws Exception { final LinkedHashMap r = new LinkedHashMap<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(pathOf("gitgit.lsfiles")), UTF_8))) { + new FileInputStream(pathOf("gitgit.lsfiles")), CHARSET))) { String line; while ((line = br.readLine()) != null) { final CGitIndexRecord cr = new CGitIndexRecord(line); @@ -249,7 +249,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { private static Map readLsTree() throws Exception { final LinkedHashMap r = new LinkedHashMap<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(pathOf("gitgit.lstree")), UTF_8))) { + new FileInputStream(pathOf("gitgit.lstree")), CHARSET))) { String line; while ((line = br.readLine()) != null) { final CGitLsTreeRecord cr = new CGitLsTreeRecord(line); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java index c9673a688..69a48cc4b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.gitrepo; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -82,7 +82,7 @@ public class ManifestParserTest { ManifestParser parser = new ManifestParser( null, null, "master", baseUrl, null, null); - parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))); + parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET))); // Unfiltered projects should have them all. results.clear(); results.add("foo"); @@ -136,7 +136,7 @@ public class ManifestParserTest { baseUrl, null, null); try { parser.read(new ByteArrayInputStream( - xmlContent.toString().getBytes(UTF_8))); + xmlContent.toString().getBytes(CHARSET))); fail("ManifestParser did not throw exception for missing fetch"); } catch (IOException e) { assertTrue(e.getCause() instanceof SAXException); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index 2253a0421..6f6dd5f46 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.gitrepo; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -214,7 +214,7 @@ public class RepoCommandTest extends RepositoryTestCase { RevCommit commit = cmd .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(UTF_8))) + xmlContent.toString().getBytes(CHARSET))) .setRemoteReader(repos) .setURI("platform/") .setTargetURI("platform/superproject") @@ -225,7 +225,7 @@ public class RepoCommandTest extends RepositoryTestCase { String firstIdStr = commit.getId().name() + ":" + ".gitmodules"; commit = new RepoCommand(dest) .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(UTF_8))) + xmlContent.toString().getBytes(CHARSET))) .setRemoteReader(repos) .setURI("platform/") .setTargetURI("platform/superproject") @@ -266,7 +266,7 @@ public class RepoCommandTest extends RepositoryTestCase { repos.put("platform/base", child); RevCommit commit = cmd - .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))) + .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET))) .setRemoteReader(repos) .setURI("platform/") .setTargetURI("platform/superproject") @@ -308,7 +308,7 @@ public class RepoCommandTest extends RepositoryTestCase { RevCommit commit = new RepoCommand(dest) .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(UTF_8))) + xmlContent.toString().getBytes(CHARSET))) .setRemoteReader(new IndexedRepos()) .setURI("platform/") .setTargetURI("platform/superproject") @@ -358,7 +358,7 @@ public class RepoCommandTest extends RepositoryTestCase { repos.put("plugins/cookbook", child); RevCommit commit = cmd - .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))) + .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET))) .setRemoteReader(repos) .setURI("") .setTargetURI("gerrit") @@ -412,7 +412,7 @@ public class RepoCommandTest extends RepositoryTestCase { repos.put(repoUrl, child); RevCommit commit = cmd - .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))) + .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET))) .setRemoteReader(repos) .setURI(baseUrl) .setTargetURI("gerrit") @@ -469,7 +469,7 @@ public class RepoCommandTest extends RepositoryTestCase { repos.put(repoUrl, child); RevCommit commit = cmd - .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))) + .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET))) .setRemoteReader(repos) .setURI(baseUrl) .setTargetURI(abs + "/superproject") diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java index 17c7ef139..80595feff 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.ignore; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -765,6 +765,6 @@ public class IgnoreNodeTest extends RepositoryTestCase { for (String line : rules) { data.append(line + "\n"); } - return new ByteArrayInputStream(data.toString().getBytes(UTF_8)); + return new ByteArrayInputStream(data.toString().getBytes(CHARSET)); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java index d5d3857ca..26c11c7eb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java @@ -41,7 +41,7 @@ */ package org.eclipse.jgit.indexdiff; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -128,7 +128,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, UTF_8)) { + Writer writer = new OutputStreamWriter(out, CHARSET)) { writer.write("echo `which git` 1>&2\n"); writer.write("echo `git --version` 1>&2\n"); writer.write("git init " + name + " && \\\n"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java index 52861ecd5..592d0c867 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.internal.storage.file; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -252,7 +252,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { ObjectId blobId; try (ObjectInserter ins = bareRepo.newObjectInserter()) { - blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(UTF_8)); + blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(CHARSET)); ins.flush(); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java index d7505af4c..b5d648560 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java @@ -47,7 +47,7 @@ package org.eclipse.jgit.internal.storage.file; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -522,7 +522,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase { 4294967295000L, 60)); commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com", 4294967295000L, 60)); - commit.setEncoding(UTF_8); + commit.setEncoding(CHARSET); commit.setMessage("\u00dcbergeeks"); ObjectId cid = insertCommit(commit); assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java index b7027f327..965899e7a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.junit; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -418,6 +418,6 @@ public class TestRepositoryTest { RevObject obj = tr.get(rw.parseTree(treeish), path); assertSame(RevBlob.class, obj.getClass()); ObjectLoader loader = rw.getObjectReader().open(obj); - return new String(loader.getCachedBytes(), UTF_8); + return new String(loader.getCachedBytes(), CHARSET); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java index f1c62d4be..22c66cec1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java @@ -45,7 +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.lib.Constants.CHARSET; 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; @@ -1454,7 +1454,7 @@ public class ObjectCheckerTest { StringBuilder b = new StringBuilder(); entry(b, "100644 A"); entry(b, "100644 a"); - byte[] data = b.toString().getBytes(UTF_8); + byte[] data = b.toString().getBytes(CHARSET); checker.setSafeForWindows(true); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); @@ -1468,7 +1468,7 @@ public class ObjectCheckerTest { StringBuilder b = new StringBuilder(); entry(b, "100644 A"); entry(b, "100644 a"); - byte[] data = b.toString().getBytes(UTF_8); + byte[] data = b.toString().getBytes(CHARSET); checker.setSafeForMacOS(true); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); @@ -1482,7 +1482,7 @@ public class ObjectCheckerTest { 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(CHARSET); checker.setSafeForMacOS(true); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); @@ -1496,7 +1496,7 @@ public class ObjectCheckerTest { StringBuilder b = new StringBuilder(); entry(b, "100644 A"); checker.setSafeForMacOS(true); - checker.checkTree(b.toString().getBytes(UTF_8)); + checker.checkTree(b.toString().getBytes(CHARSET)); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java index 9322a4734..9734ac851 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.merge; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -756,7 +756,7 @@ public class ResolveMergerTest extends RepositoryTestCase { } binary[50] = '\0'; - writeTrashFile("file", new String(binary, UTF_8)); + writeTrashFile("file", new String(binary, CHARSET)); git.add().addFilepattern("file").call(); RevCommit first = git.commit().setMessage("added file").call(); @@ -764,7 +764,7 @@ public class ResolveMergerTest extends RepositoryTestCase { int idx = LINELEN * 1200 + 1; byte save = binary[idx]; binary[idx] = '@'; - writeTrashFile("file", new String(binary, UTF_8)); + writeTrashFile("file", new String(binary, CHARSET)); binary[idx] = save; git.add().addFilepattern("file").call(); @@ -773,7 +773,7 @@ public class ResolveMergerTest extends RepositoryTestCase { git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call(); binary[LINELEN * 1500 + 1] = '!'; - writeTrashFile("file", new String(binary, UTF_8)); + writeTrashFile("file", new String(binary, CHARSET)); git.add().addFilepattern("file").call(); RevCommit sideCommit = git.commit().setAll(true) .setMessage("modified file l 1500").call(); @@ -935,7 +935,7 @@ public class ResolveMergerTest extends RepositoryTestCase { merger.getMergeResults().get("file"); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { fmt.formatMerge(out, merger.getMergeResults().get("file"), - "BASE", "OURS", "THEIRS", UTF_8.name()); + "BASE", "OURS", "THEIRS", CHARSET.name()); String expected = "<<<<<<< OURS\n" + "1master\n" + "=======\n" @@ -943,7 +943,7 @@ public class ResolveMergerTest extends RepositoryTestCase { + ">>>>>>> THEIRS\n" + "2\n" + "3"; - assertEquals(expected, new String(out.toByteArray(), UTF_8)); + assertEquals(expected, new String(out.toByteArray(), CHARSET)); } } } @@ -1328,6 +1328,6 @@ public class ResolveMergerTest extends RepositoryTestCase { if (obj == null) { return null; } - return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), UTF_8); + return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), CHARSET); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java index 65375c7ae..8da199f7c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.patch; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -83,7 +83,7 @@ public class GetTextTest { @Test public void testGetText_Convert() throws IOException { final Charset csOld = ISO_8859_1; - final Charset csNew = UTF_8; + final Charset csNew = CHARSET; final Patch p = parseTestPatchFile(); assertTrue(p.getErrors().isEmpty()); assertEquals(1, p.getFiles().size()); @@ -103,7 +103,7 @@ public class GetTextTest { @Test public void testGetText_DiffCc() throws IOException { final Charset csOld = ISO_8859_1; - final Charset csNew = UTF_8; + final Charset csNew = CHARSET; final Patch p = parseTestPatchFile(); assertTrue(p.getErrors().isEmpty()); assertEquals(1, p.getFiles().size()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java index 88f240bb1..9fc96212c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java @@ -44,7 +44,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.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -114,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(CHARSET)); assertNotNull(c.getTree()); assertEquals(treeId, c.getTree().getId()); assertSame(rw.lookupTree(treeId), c.getTree()); @@ -148,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(CHARSET)); return c; } @@ -161,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(CHARSET)); assertEquals("", c.getFullMessage()); assertEquals("", c.getShortMessage()); @@ -176,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(CHARSET)); assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent()); assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent()); @@ -185,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 1218123387 +0700\n".getBytes(UTF_8)); - b.write("committer C O. Miter 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(CHARSET)); + b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(CHARSET)); + b.write("committer C O. Miter 1218123390 -0500\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); final RevCommit c; c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new RevWalk(db), b.toByteArray()); @@ -205,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("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(ISO_8859_1)); - b.write("committer C O. Miter 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("committer C O. Miter 1218123390 -0500\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); final RevCommit c; c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new RevWalk(db), b.toByteArray()); @@ -260,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("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(ISO_8859_1)); - b.write("committer C O. Miter 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("committer C O. Miter 1218123390 -0500\n".getBytes(CHARSET)); + b.write("encoding EUC-JP\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Hi\n".getBytes(CHARSET)); final RevCommit c; c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new RevWalk(db), b.toByteArray()); @@ -291,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 1218123387 +0700\n".getBytes(UTF_8)); - b.write("committer C O. Miter 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(CHARSET)); + b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(CHARSET)); + b.write("committer C O. Miter 1218123390 -0500\n".getBytes(CHARSET)); + b.write("encoding ISO-8859-1\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Hi\n".getBytes(CHARSET)); final RevCommit c; c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new RevWalk(db), b.toByteArray()); @@ -313,13 +313,13 @@ public class RevCommitParseTest extends RepositoryTestCase { public void testParse_incorrectUtf8Name() throws Exception { ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n" - .getBytes(UTF_8)); - b.write("author au 1218123387 +0700\n".getBytes(UTF_8)); + .getBytes(CHARSET)); + b.write("author au 1218123387 +0700\n".getBytes(CHARSET)); b.write("committer co 1218123390 -0500\n" - .getBytes(UTF_8)); - b.write("encoding 'utf8'\n".getBytes(UTF_8)); - b.write("\n".getBytes(UTF_8)); - b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8)); + .getBytes(CHARSET)); + b.write("encoding 'utf8'\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); RevCommit c = new RevCommit( id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); @@ -338,12 +338,12 @@ public class RevCommitParseTest extends RepositoryTestCase { @Test public void testParse_illegalEncoding() throws Exception { ByteArrayOutputStream b = new ByteArrayOutputStream(); - b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); - b.write("author au 1218123387 +0700\n".getBytes(UTF_8)); - b.write("committer co 1218123390 -0500\n".getBytes(UTF_8)); - b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8)); - b.write("\n".getBytes(UTF_8)); - b.write("message\n".getBytes(UTF_8)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); + b.write("author au 1218123387 +0700\n".getBytes(CHARSET)); + b.write("committer co 1218123390 -0500\n".getBytes(CHARSET)); + b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("message\n".getBytes(CHARSET)); RevCommit c = new RevCommit( id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); @@ -365,12 +365,12 @@ public class RevCommitParseTest extends RepositoryTestCase { @Test public void testParse_unsupportedEncoding() throws Exception { ByteArrayOutputStream b = new ByteArrayOutputStream(); - b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); - b.write("author au 1218123387 +0700\n".getBytes(UTF_8)); - b.write("committer co 1218123390 -0500\n".getBytes(UTF_8)); - b.write("encoding it_IT.UTF8\n".getBytes(UTF_8)); - b.write("\n".getBytes(UTF_8)); - b.write("message\n".getBytes(UTF_8)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); + b.write("author au 1218123387 +0700\n".getBytes(CHARSET)); + b.write("committer co 1218123390 -0500\n".getBytes(CHARSET)); + b.write("encoding it_IT.UTF8\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("message\n".getBytes(CHARSET)); RevCommit c = new RevCommit( id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java index 38bd371b9..8e9507961 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java @@ -44,7 +44,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.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -98,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(CHARSET)); assertNotNull(c.getObject()); assertEquals(id, c.getObject().getId()); assertSame(rw.lookupAny(id, typeCode), c.getObject()); @@ -141,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(CHARSET)); assertNotNull(c.getObject()); assertEquals(treeId, c.getObject().getId()); assertSame(rw.lookupTree(treeId), c.getObject()); @@ -189,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(CHARSET)); assertNotNull(c.getObject()); assertEquals(treeId, c.getObject().getId()); assertSame(rw.lookupTree(treeId), c.getObject()); @@ -213,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(CHARSET)); return c; } @@ -221,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(CHARSET)); + b.write("type tree\n".getBytes(CHARSET)); + b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); b .write("tagger F\u00f6r fattare 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(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); final RevTag c; c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c.parseCanonical(new RevWalk(db), b.toByteArray()); @@ -246,15 +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)); + .getBytes(CHARSET)); + b.write("type tree\n".getBytes(CHARSET)); + b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); b.write("tagger F\u00f6r fattare 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)); + b.write("\n".getBytes(CHARSET)); + b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); 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(CHARSET)); + b.write("type tree\n".getBytes(CHARSET)); + b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); b .write("tagger F\u00f6r fattare 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)); + b.write("encoding EUC-JP\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Hi\n".getBytes(CHARSET)); 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(CHARSET)); + b.write("type tree\n".getBytes(CHARSET)); + b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); b .write("tagger F\u00f6r fattare 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(CHARSET)); + b.write("encoding ISO-8859-1\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("\u304d\u308c\u3044\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("Hi\n".getBytes(CHARSET)); final RevTag c; c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c.parseCanonical(new RevWalk(db), b.toByteArray()); @@ -365,13 +365,13 @@ public class RevTagParseTest extends RepositoryTestCase { @Test public void testParse_illegalEncoding() throws Exception { ByteArrayOutputStream b = new ByteArrayOutputStream(); - b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); - b.write("type tree\n".getBytes(UTF_8)); - b.write("tag v1.0\n".getBytes(UTF_8)); - b.write("tagger t 1218123387 +0700\n".getBytes(UTF_8)); - b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8)); - b.write("\n".getBytes(UTF_8)); - b.write("message\n".getBytes(UTF_8)); + b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); + b.write("type tree\n".getBytes(CHARSET)); + b.write("tag v1.0\n".getBytes(CHARSET)); + b.write("tagger t 1218123387 +0700\n".getBytes(CHARSET)); + b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("message\n".getBytes(CHARSET)); RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); t.parseCanonical(new RevWalk(db), b.toByteArray()); @@ -384,13 +384,13 @@ public class RevTagParseTest extends RepositoryTestCase { @Test public void testParse_unsupportedEncoding() throws Exception { ByteArrayOutputStream b = new ByteArrayOutputStream(); - b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); - b.write("type tree\n".getBytes(UTF_8)); - b.write("tag v1.0\n".getBytes(UTF_8)); - b.write("tagger t 1218123387 +0700\n".getBytes(UTF_8)); - b.write("encoding it_IT.UTF8\n".getBytes(UTF_8)); - b.write("\n".getBytes(UTF_8)); - b.write("message\n".getBytes(UTF_8)); + b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET)); + b.write("type tree\n".getBytes(CHARSET)); + b.write("tag v1.0\n".getBytes(CHARSET)); + b.write("tagger t 1218123387 +0700\n".getBytes(CHARSET)); + b.write("encoding it_IT.UTF8\n".getBytes(CHARSET)); + b.write("\n".getBytes(CHARSET)); + b.write("message\n".getBytes(CHARSET)); RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); t.parseCanonical(new RevWalk(db), b.toByteArray()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java index 7f0d60295..0dea5ce97 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.storage.file; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.util.FileUtils.pathToString; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -105,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(CHARSET)); final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); config.load(); assertEquals(ALICE, config.getString(USER, null, NAME)); @@ -121,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(CHARSET)); final File file = createFile(bos1.toByteArray()); final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); @@ -135,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(CHARSET)); assertArrayEquals(bos2.toByteArray(), IO.readFully(file)); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index 658b971ac..d30ac840a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -199,7 +199,7 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase { Ref ref = repo.exactRef(refName); assertNotNull(ref); assertEquals(id, ref.getObjectId()); - assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), UTF_8)); + assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), CHARSET)); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java index cb04f83fb..2251a3dc6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE; import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans; import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete; @@ -360,7 +360,7 @@ public class WalkEncryptionTest { * @throws Exception */ static String textRead(File file) throws Exception { - return new String(Files.readAllBytes(file.toPath()), UTF_8); + return new String(Files.readAllBytes(file.toPath()), CHARSET); } /** @@ -371,7 +371,7 @@ public class WalkEncryptionTest { * @throws Exception */ static void textWrite(File file, String text) throws Exception { - Files.write(file.toPath(), text.getBytes(UTF_8)); + Files.write(file.toPath(), text.getBytes(CHARSET)); } static void verifyFileContent(File fileOne, File fileTwo) @@ -741,7 +741,7 @@ public class WalkEncryptionTest { AmazonS3 s3 = new AmazonS3(props); String file = JGIT_USER + "-" + UUID.randomUUID().toString(); String path = JGIT_REMOTE_DIR + "/" + file; - s3.put(bucket, path, file.getBytes(UTF_8)); + s3.put(bucket, path, file.getBytes(CHARSET)); s3.delete(bucket, path); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java index e8566d243..a748b5221 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.util; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -93,7 +93,7 @@ public class RawSubStringPatternTest extends RepositoryTestCase { } private static RawCharSequence raw(String text) { - byte[] bytes = text.getBytes(UTF_8); + byte[] bytes = text.getBytes(CHARSET); return new RawCharSequence(bytes, 0, bytes.length); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java index 38199d8aa..8b955bae6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.util.io; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; @@ -129,6 +129,6 @@ public class AutoLFInputStreamTest { } private static byte[] asBytes(String in) { - return in.getBytes(UTF_8); + return in.getBytes(CHARSET); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java index e6045a91b..3c612e1bd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.util.sha1; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -95,15 +95,15 @@ public class SHA1Test { .fromString("a9993e364706816aba3e25717850c26c9cd0d89d"); MessageDigest m = MessageDigest.getInstance("SHA-1"); - m.update(TEST1.getBytes(UTF_8)); + m.update(TEST1.getBytes(CHARSET)); ObjectId m1 = ObjectId.fromRaw(m.digest()); SHA1 s = SHA1.newInstance(); - s.update(TEST1.getBytes(UTF_8)); + s.update(TEST1.getBytes(CHARSET)); ObjectId s1 = ObjectId.fromRaw(s.digest()); s.reset(); - s.update(TEST1.getBytes(UTF_8)); + s.update(TEST1.getBytes(CHARSET)); 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(UTF_8)); + m.update(TEST2.getBytes(CHARSET)); ObjectId m1 = ObjectId.fromRaw(m.digest()); SHA1 s = SHA1.newInstance(); - s.update(TEST2.getBytes(UTF_8)); + s.update(TEST2.getBytes(CHARSET)); ObjectId s1 = ObjectId.fromRaw(s.digest()); s.reset(); - s.update(TEST2.getBytes(UTF_8)); + s.update(TEST2.getBytes(CHARSET)); ObjectId s2 = s.toObjectId(); assertEquals(m1, s1); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java index ad43e2ca8..8a61d1b0b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.hooks; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -158,7 +158,7 @@ abstract class GitHook implements Callable { PrintStream hookErrRedirect = null; try { hookErrRedirect = new PrintStream(errorByteArray, false, - UTF_8.name()); + CHARSET.name()); } catch (UnsupportedEncodingException e) { // UTF-8 is guaranteed to be available } @@ -167,7 +167,7 @@ abstract class GitHook implements Callable { hookErrRedirect, getStdinArgs()); if (result.isExecutedWithError()) { throw new AbortedByHookException( - new String(errorByteArray.toByteArray(), UTF_8), + new String(errorByteArray.toByteArray(), CHARSET), getHookName(), result.getExitCode()); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java index 8793d8312..c11f69670 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.dfs; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.util.Arrays; @@ -67,7 +67,7 @@ public abstract class DfsStreamKey { */ public static DfsStreamKey of(DfsRepositoryDescription repo, String name, @Nullable PackExt ext) { - return new ByteArrayDfsStreamKey(repo, name.getBytes(UTF_8), ext); + return new ByteArrayDfsStreamKey(repo, name.getBytes(CHARSET), ext); } final int hash; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java index bca7076ac..c159a9470 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.file; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedReader; import java.io.File; @@ -187,6 +187,6 @@ class GcLog { if (content.length() > 0) { nonEmpty = true; } - lock.write(content.getBytes(UTF_8)); + lock.write(content.getBytes(CHARSET)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java index 3d0e9c718..c82d52e79 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.file; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedReader; import java.io.File; @@ -86,7 +86,7 @@ public class LazyObjectIdSetFile implements ObjectIdSet { private ObjectIdOwnerMap load() { ObjectIdOwnerMap r = new ObjectIdOwnerMap<>(); try (FileInputStream fin = new FileInputStream(src); - Reader rin = new InputStreamReader(fin, UTF_8); + Reader rin = new InputStreamReader(fin, CHARSET); BufferedReader br = new BufferedReader(rin)) { MutableObjectId id = new MutableObjectId(); for (String line; (line = br.readLine()) != null;) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java index ce2ba4a2e..942d72fe2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.BlockWriter.compare; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; @@ -138,7 +138,7 @@ class BlockReader { if (blockType == LOG_BLOCK_TYPE) { len -= 9; } - return RawParseUtils.decode(UTF_8, nameBuf, 0, len); + return RawParseUtils.decode(CHARSET, nameBuf, 0, len); } boolean match(byte[] match, boolean matchIsPrefix) { @@ -171,7 +171,7 @@ class BlockReader { } Ref readRef() throws IOException { - String name = RawParseUtils.decode(UTF_8, nameBuf, 0, nameLen); + String name = RawParseUtils.decode(CHARSET, nameBuf, 0, nameLen); switch (valueType & VALUE_TYPE_MASK) { case VALUE_NONE: // delete return newRef(name); @@ -266,7 +266,7 @@ class BlockReader { private String readValueString() { int len = readVarint32(); int end = ptr + len; - String s = RawParseUtils.decode(UTF_8, buf, ptr, end); + String s = RawParseUtils.decode(CHARSET, buf, ptr, end); ptr = end; return s; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java index b3173e838..3d8fbf499 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; @@ -440,7 +440,7 @@ class BlockWriter { } private static byte[] nameUtf8(Ref ref) { - return ref.getName().getBytes(UTF_8); + return ref.getName().getBytes(CHARSET); } } @@ -559,13 +559,13 @@ class BlockWriter { this.newId = newId; this.timeSecs = who.getWhen().getTime() / 1000L; this.tz = (short) who.getTimeZoneOffset(); - this.name = who.getName().getBytes(UTF_8); - this.email = who.getEmailAddress().getBytes(UTF_8); - this.msg = message.getBytes(UTF_8); + this.name = who.getName().getBytes(CHARSET); + this.email = who.getEmailAddress().getBytes(CHARSET); + this.msg = message.getBytes(CHARSET); } static byte[] key(String ref, long index) { - byte[] name = ref.getBytes(UTF_8); + byte[] name = ref.getBytes(CHARSET); byte[] key = Arrays.copyOf(name, name.length + 1 + 8); NB.encodeInt64(key, key.length - 8, reverseUpdateIndex(index)); return key; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java index 1fc43c9fa..44bbb1621 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; @@ -160,7 +160,7 @@ class ReftableOutputStream extends OutputStream { } void writeVarintString(String s) { - writeVarintString(s.getBytes(UTF_8)); + writeVarintString(s.getBytes(CHARSET)); } void writeVarintString(byte[] msg) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java index 74877192f..5356952b5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.BlockReader.decodeBlockLen; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_FOOTER_LEN; @@ -182,7 +182,7 @@ public class ReftableReader extends Reftable { public RefCursor seekRef(String refName) throws IOException { initRefIndex(); - byte[] key = refName.getBytes(UTF_8); + byte[] key = refName.getBytes(CHARSET); boolean prefix = key[key.length - 1] == '/'; RefCursorImpl i = new RefCursorImpl(refEnd, key, prefix); @@ -223,7 +223,7 @@ public class ReftableReader extends Reftable { initLogIndex(); if (logPosition > 0) { byte[] key = LogEntry.key(refName, updateIndex); - byte[] match = refName.getBytes(UTF_8); + byte[] match = refName.getBytes(CHARSET); LogCursorImpl i = new LogCursorImpl(logEnd, match); i.block = seek(LOG_BLOCK_TYPE, key, logIndex, logPosition, logEnd); return i; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java index 3ff92dc73..f44aeceb5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.lib; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.io.FileNotFoundException; import java.io.IOException; import java.text.MessageFormat; @@ -81,8 +83,7 @@ public class BlobBasedConfig extends Config { super(base); final String decoded; if (isUtf8(blob)) { - decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, - blob, 3, blob.length); + decoded = RawParseUtils.decode(CHARSET, blob, 3, blob.length); } else { decoded = RawParseUtils.decode(blob); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 4d558c9fc..285a56c87 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -51,6 +51,8 @@ package org.eclipse.jgit.lib; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -1166,8 +1168,7 @@ public class Config { String decoded; if (isUtf8(bytes)) { - decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, bytes, 3, - bytes.length); + decoded = RawParseUtils.decode(CHARSET, bytes, 3, bytes.length); } else { decoded = RawParseUtils.decode(bytes); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index 29189a9d7..5c7cee6ca 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -228,10 +228,10 @@ public final class Constants { public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' }; /** Native character encoding for commit messages, file names... */ - public static final Charset CHARSET = UTF_8; + public static final Charset CHARSET; /** Native character encoding for commit messages, file names... */ - public static final String CHARACTER_ENCODING = CHARSET.name(); + public static final String CHARACTER_ENCODING; /** Default main branch name */ public static final String MASTER = "master"; @@ -654,6 +654,8 @@ public final class Constants { static { if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength()) throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH); + CHARSET = UTF_8; + CHARACTER_ENCODING = CHARSET.name(); } /** name of the file containing the commit msg for a merge commit */ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java index 06b4b227c..38716055b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.lib; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedOutputStream; import java.io.File; @@ -183,7 +183,7 @@ public class RebaseTodoFile { switch (tokenCount) { case 0: String actionToken = new String(buf, tokenBegin, - nextSpace - tokenBegin - 1, UTF_8); + nextSpace - tokenBegin - 1, CHARSET); tokenBegin = nextSpace; action = RebaseTodoLine.Action.parse(actionToken); if (action == null) @@ -192,7 +192,7 @@ public class RebaseTodoFile { case 1: nextSpace = RawParseUtils.next(buf, tokenBegin, ' '); String commitToken = new String(buf, tokenBegin, - nextSpace - tokenBegin - 1, UTF_8); + nextSpace - tokenBegin - 1, CHARSET); tokenBegin = nextSpace; commit = AbbreviatedObjectId.fromString(commitToken); break; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java index 936ce3dcc..2f759e53c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.lib; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.io.OutputStreamWriter; @@ -63,7 +63,7 @@ public class TextProgressMonitor extends BatchingProgressMonitor { * Initialize a new progress monitor. */ public TextProgressMonitor() { - this(new PrintWriter(new OutputStreamWriter(System.err, UTF_8))); + this(new PrintWriter(new OutputStreamWriter(System.err, CHARSET))); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java index 9db146706..5c8371f91 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.revwalk; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.nio.charset.Charset; @@ -539,7 +539,7 @@ public class RevCommit extends RevObject { try { return getEncoding(); } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { - return UTF_8; + return CHARSET; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java index d74837e86..cbeda71a8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.revwalk; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.nio.charset.Charset; @@ -169,7 +169,7 @@ public class RevTag extends RevObject { int p = pos.value += 4; // "tag " final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1; - tagName = RawParseUtils.decode(UTF_8, rawTag, p, nameEnd); + tagName = RawParseUtils.decode(CHARSET, rawTag, p, nameEnd); if (walk.isRetainBody()) buffer = rawTag; @@ -257,7 +257,7 @@ public class RevTag extends RevObject { try { return RawParseUtils.parseEncoding(buffer); } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { - return UTF_8; + return CHARSET; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java index 9927daf3d..93ffb944c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java @@ -49,6 +49,8 @@ package org.eclipse.jgit.storage.file; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -154,7 +156,7 @@ public class FileBasedConfig extends StoredConfig { } else { final String decoded; if (isUtf8(in)) { - decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, + decoded = RawParseUtils.decode(CHARSET, in, 3, in.length); utf8Bom = true; } else { @@ -198,7 +200,7 @@ public class FileBasedConfig extends StoredConfig { bos.write(0xEF); bos.write(0xBB); bos.write(0xBF); - bos.write(text.getBytes(RawParseUtils.UTF8_CHARSET.name())); + bos.write(text.getBytes(CHARSET)); out = bos.toByteArray(); } else { out = Constants.encode(text); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index d7c5b9d7f..71e3d16c4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.ByteArrayOutputStream; import java.io.File; @@ -638,7 +638,7 @@ public class AmazonS3 { try { final Mac m = Mac.getInstance(HMAC); m.init(privateKey); - sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(UTF_8))); + sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(CHARSET))); } catch (NoSuchAlgorithmException e) { throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage())); } catch (InvalidKeyException e) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java index 6c26b7026..1415334c6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.File; import java.security.InvalidKeyException; @@ -102,7 +102,7 @@ public class HMACSHA1NonceGenerator implements NonceGenerator { } String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$ - byte[] rawHmac = mac.doFinal(input.getBytes(UTF_8)); + byte[] rawHmac = mac.doFinal(input.getBytes(CHARSET)); return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$ } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java index c40d9635d..de7a7dc1c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE; @@ -315,7 +315,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)); + String enc = Base64.encodeBytes(ident.getBytes(CHARSET)); conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName() + " " + enc); //$NON-NLS-1$ } @@ -430,15 +430,15 @@ abstract class HttpAuthMethod { private static String H(String data) { MessageDigest md = newMD5(); - md.update(data.getBytes(UTF_8)); + md.update(data.getBytes(CHARSET)); return LHEX(md.digest()); } private static String KD(String secret, String data) { MessageDigest md = newMD5(); - md.update(secret.getBytes(UTF_8)); + md.update(secret.getBytes(CHARSET)); md.update((byte) ':'); - md.update(data.getBytes(UTF_8)); + md.update(data.getBytes(CHARSET)); return LHEX(md.digest()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java index 41af8078c..2364434b0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.io.OutputStream; @@ -141,7 +141,7 @@ public class ProgressSpinner { private void write(String s) { if (write) { try { - out.write(s.getBytes(UTF_8)); + out.write(s.getBytes(CHARSET)); out.flush(); } catch (IOException e) { write = false; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java index f9fddbe88..178c80d22 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.util.RawParseUtils.lastIndexOfTrim; import java.text.SimpleDateFormat; @@ -95,7 +95,7 @@ public class PushCertificateIdent { */ public static PushCertificateIdent parse(String str) { MutableInteger p = new MutableInteger(); - byte[] raw = str.getBytes(UTF_8); + byte[] raw = str.getBytes(CHARSET); int tzBegin = raw.length - 1; tzBegin = lastIndexOfTrim(raw, ' ', tzBegin); if (tzBegin < 0 || raw[tzBegin] != ' ') { @@ -129,7 +129,7 @@ public class PushCertificateIdent { idEnd = raw.length; } } - String id = new String(raw, 0, idEnd, UTF_8); + String id = new String(raw, 0, idEnd, CHARSET); return new PushCertificateIdent(str, id, when * 1000L, tz); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java index ab58a3317..36d660234 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT; import static org.eclipse.jgit.lib.FileMode.TYPE_FILE; @@ -292,7 +292,7 @@ public class PushCertificateStore implements AutoCloseable { ObjectLoader loader = tw.getObjectReader().open(tw.getObjectId(0), OBJ_BLOB); try (InputStream in = loader.openStream(); - Reader r = new BufferedReader(new InputStreamReader(in, UTF_8))) { + Reader r = new BufferedReader(new InputStreamReader(in, CHARSET))) { return PushCertificateParser.fromReader(r); } } @@ -473,7 +473,7 @@ public class PushCertificateStore implements AutoCloseable { DirCacheEditor editor = dc.editor(); String certText = pc.cert.toText() + pc.cert.getSignature(); - final ObjectId certId = inserter.insert(OBJ_BLOB, certText.getBytes(UTF_8)); + final ObjectId certId = inserter.insert(OBJ_BLOB, certText.getBytes(CHARSET)); boolean any = false; for (ReceiveCommand cmd : pc.cert.getCommands()) { if (byRef != null && !commandsEqual(cmd, byRef.get(cmd.getRefName()))) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java index 5eb166173..6ad39e3dd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SYMREF; @@ -74,7 +74,7 @@ import org.eclipse.jgit.util.RefMap; public abstract class RefAdvertiser { /** Advertiser which frames lines in a {@link PacketLineOut} format. */ public static class PacketLineOutRefAdvertiser extends RefAdvertiser { - private final CharsetEncoder utf8 = UTF_8.newEncoder(); + private final CharsetEncoder utf8 = CHARSET.newEncoder(); private final PacketLineOut pckOut; private byte[] binArr = new byte[256]; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index 8db796a83..ce321b014 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.transport; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.RefDatabase.ALL; import java.io.BufferedReader; @@ -147,7 +148,7 @@ public abstract class Transport implements AutoCloseable { BufferedReader br; try { InputStream urlIn = url.openStream(); - br = new BufferedReader(new InputStreamReader(urlIn, "UTF-8")); //$NON-NLS-1$ + br = new BufferedReader(new InputStreamReader(urlIn, CHARSET)); } catch (IOException err) { // If we cannot read from the service list, go to the next. // diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java index 0c27ced76..442f0793f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java @@ -6,9 +6,8 @@ package org.eclipse.jgit.util; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; -import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.util.Arrays; @@ -55,7 +54,7 @@ public class Base64 { + "abcdefghijklmnopqrstuvwxyz" // //$NON-NLS-1$ + "0123456789" // //$NON-NLS-1$ + "+/" // //$NON-NLS-1$ - ).getBytes(UTF_8); + ).getBytes(CHARSET); DEC = new byte[128]; Arrays.fill(DEC, INVALID_DEC); @@ -178,7 +177,7 @@ public class Base64 { e += 4; } - return new String(outBuff, 0, e, StandardCharsets.UTF_8); + return new String(outBuff, 0, e, CHARSET); } /** @@ -294,7 +293,7 @@ public class Base64 { * @return the decoded data */ public static byte[] decode(String s) { - byte[] bytes = s.getBytes(UTF_8); + byte[] bytes = s.getBytes(CHARSET); return decode(bytes, 0, bytes.length); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java index 64cdcc300..0b0a5057c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.util; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.io.File; import java.io.PrintStream; import java.nio.file.Files; @@ -124,7 +126,7 @@ public class FS_Win32_Cygwin extends FS_Win32 { try { w = readPipe(dir, // new String[] { cygpath, "--windows", "--absolute", pn }, // //$NON-NLS-1$ //$NON-NLS-2$ - "UTF-8"); //$NON-NLS-1$ + CHARSET.name()); } catch (CommandFailedException e) { LOG.warn(e.getMessage()); return null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java index a5a858f85..d070ed39d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java @@ -44,6 +44,8 @@ package org.eclipse.jgit.util; +import static org.eclipse.jgit.lib.Constants.CHARACTER_ENCODING; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.ConnectException; @@ -179,7 +181,7 @@ public class HttpSupport { if (key == null || key.length() == 0) return; try { - urlstr.append(URLEncoder.encode(key, "UTF-8")); //$NON-NLS-1$ + urlstr.append(URLEncoder.encode(key, CHARACTER_ENCODING)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(JGitText.get().couldNotURLEncodeToUTF8, e); }