]> source.dussan.org Git - jgit.git/commitdiff
Remove UTF-8 checking duplication in Config lib subclasses 15/72315/2
authorMarco Miller <marco.miller@ericsson.com>
Mon, 9 May 2016 16:36:00 +0000 (12:36 -0400)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 11 May 2016 22:14:17 +0000 (00:14 +0200)
Change-Id: Ib9f0ae8207000a36c5bf1a92fcc2c32efc4c0984
Signed-off-by: Marco Miller <marco.miller@ericsson.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

index 7d52991df0fd69906addbc1a0e1706978f25addb..8958ce7e858435daa229363ba1708d91cf609f68 100644 (file)
@@ -80,8 +80,7 @@ public class BlobBasedConfig extends Config {
                        throws ConfigInvalidException {
                super(base);
                final String decoded;
-               if (blob.length >= 3 && blob[0] == (byte) 0xEF
-                               && blob[1] == (byte) 0xBB && blob[2] == (byte) 0xBF) {
+               if (isUtf8(blob)) {
                        decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET,
                                        blob, 3, blob.length);
                } else {
index 088dcdfd043080bfda5e4399fc03fa031d2cb216..567e31642d07398dc1a08402aca27accd0ccfae9 100644 (file)
@@ -1108,6 +1108,19 @@ public class Config {
                state.set(newState());
        }
 
+       /**
+        * Check if bytes should be treated as UTF-8 or not.
+        *
+        * @param bytes
+        *            the bytes to check encoding for.
+        * @return true if bytes should be treated as UTF-8, false otherwise.
+        * @since 4.4
+        */
+       protected boolean isUtf8(final byte[] bytes) {
+               return bytes.length >= 3 && bytes[0] == (byte) 0xEF
+                               && bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF;
+       }
+
        private static String readSectionName(final StringReader in)
                        throws ConfigInvalidException {
                final StringBuilder name = new StringBuilder();
index 702fd70765a9c7d401449873fa83548902be752e..4b4822c7635559b0db892dfafd6fc5bef5acd5e7 100644 (file)
@@ -147,8 +147,7 @@ public class FileBasedConfig extends StoredConfig {
                                        snapshot = newSnapshot;
                        } else {
                                final String decoded;
-                               if (in.length >= 3 && in[0] == (byte) 0xEF
-                                               && in[1] == (byte) 0xBB && in[2] == (byte) 0xBF) {
+                               if (isUtf8(in)) {
                                        decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET,
                                                        in, 3, in.length);
                                        utf8Bom = true;