You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2018/05/27 05:48:58 UTC

svn commit: r1832322 - in /jackrabbit/oak/branches/1.8: ./ oak-store-document/ oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/ oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/

Author: reschke
Date: Sun May 27 05:48:58 2018
New Revision: 1832322

URL: http://svn.apache.org/viewvc?rev=1832322&view=rev
Log:
OAK-7442: Remove dependency to commons-codec (ported to 1.8)

Modified:
    jackrabbit/oak/branches/1.8/   (props changed)
    jackrabbit/oak/branches/1.8/oak-store-document/pom.xml
    jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
    jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java

Propchange: jackrabbit/oak/branches/1.8/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun May 27 05:48:58 2018
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821237,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821663,1821665,1821668,1821681,1821847,1821975-1821983,1822121,1822201,1822207,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1823655,1824196,1824198,1824896,1824962,1825065,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826237,1826338,1826516,1826532,1826551,1826560,1826640,1826730,1826932,1826957,1827472,1827486,1827977,1828529,1829527,1829534,1829569,1829854,1829864,1829987,1829998,1830019,1830160,1830197,1830748,1831157-1831158,1831163,1831374,1831560
+/jackrabbit/oak/trunk:1820660-1820661,1820729,1820734,1820859,1820861,1820878,1820888,1820947,1821027,1821130,1821140-1821141,1821178,1821237,1821240,1821249,1821258,1821325,1821358,1821361-1821362,1821370,1821375,1821393,1821477,1821487,1821516,1821617,1821663,1821665,1821668,1821681,1821847,1821975-1821983,1822121,1822201,1822207,1822723,1822808,1822850,1822934,1823135,1823163,1823169,1823172,1823655,1824196,1824198,1824896,1824962,1825065,1825362,1825381,1825442,1825448,1825466,1825470-1825471,1825475,1825523,1825525,1825619-1825621,1825651,1825654,1825992,1826079,1826090,1826096,1826237,1826338,1826516,1826532,1826551,1826560,1826640,1826730,1826932,1826957,1827472,1827486,1827977,1828529,1829527,1829534,1829569,1829854,1829864,1829987,1829998,1830019,1830160,1830171,1830197,1830748,1831157-1831158,1831163,1831374,1831560
 /jackrabbit/trunk:1345480

Modified: jackrabbit/oak/branches/1.8/oak-store-document/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-store-document/pom.xml?rev=1832322&r1=1832321&r2=1832322&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-store-document/pom.xml (original)
+++ jackrabbit/oak/branches/1.8/oak-store-document/pom.xml Sun May 27 05:48:58 2018
@@ -145,10 +145,6 @@
       <artifactId>guava</artifactId>
     </dependency>
     <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
-    </dependency>
-    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
     </dependency>
@@ -308,6 +304,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
       <scope>test</scope>

Modified: jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java?rev=1832322&r1=1832321&r2=1832322&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java (original)
+++ jackrabbit/oak/branches/1.8/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java Sun May 27 05:48:58 2018
@@ -39,7 +39,6 @@ import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.collect.AbstractIterator;
 
-import org.apache.commons.codec.binary.Hex;
 import org.apache.jackrabbit.oak.commons.OakVersion;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.commons.StringUtils;
@@ -92,6 +91,8 @@ public class Utils {
 
     private static final Charset UTF_8 = Charset.forName("UTF-8");
 
+    private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray();
+
     /**
      * A predicate for property and _deleted names.
      */
@@ -243,13 +244,33 @@ public class Utils {
             String parent = PathUtils.getParentPath(path);
             byte[] hash = digest.digest(parent.getBytes(UTF_8));
             String name = PathUtils.getName(path);
-            return depth + ":h" + Hex.encodeHexString(hash) + "/" + name;
+            StringBuilder sb = new StringBuilder(digest.getDigestLength() * 2 + name.length() + 6);
+            sb.append(depth).append(":h");
+            encodeHexString(hash, sb).append("/").append(name);
+            return sb.toString();
         }
         int depth = Utils.pathDepth(path);
         return depth + ":" + path;
     }
 
     /**
+     * Encodes the given data as hexadecimal string representation and appends
+     * it to the {@code StringBuilder}. The hex digits are in lower case.
+     *
+     * @param data the bytes to encode.
+     * @param sb the hexadecimal string representation is appended to this
+     *           {@code StringBuilder}.
+     * @return the {@code StringBuilder} passed to this method.
+     */
+    public static StringBuilder encodeHexString(byte[] data, StringBuilder sb) {
+        for (byte b : data) {
+            sb.append(HEX_DIGITS[(b >> 4) & 0xF]);
+            sb.append(HEX_DIGITS[(b & 0xF)]);
+        }
+        return sb;
+    }
+
+    /**
      * Returns the parent id for given id if possible
      *
      * <p>It would return null in following cases

Modified: jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java?rev=1832322&r1=1832321&r2=1832322&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java (original)
+++ jackrabbit/oak/branches/1.8/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/UtilsTest.java Sun May 27 05:48:58 2018
@@ -17,11 +17,14 @@
 package org.apache.jackrabbit.oak.plugins.document.util;
 
 import java.util.List;
+import java.util.Random;
+
 
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
+import org.apache.commons.codec.binary.Hex;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
@@ -298,4 +301,17 @@ public class UtilsTest {
         assertFalse(Utils.isIdFromLongPath(NodeDocument.MAX_ID_VALUE));
         assertFalse(Utils.isIdFromLongPath(":"));
     }
+
+    @Test
+    public void encodeHexString() {
+        Random r = new Random(42);
+        for (int i = 0; i < 1000; i++) {
+            int len = r.nextInt(100);
+            byte[] data = new byte[len];
+            r.nextBytes(data);
+            // compare against commons codec implementation
+            assertEquals(Hex.encodeHexString(data),
+                    Utils.encodeHexString(data, new StringBuilder()).toString());
+        }
+    }
 }