jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1396648 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: api/Blob.java plugins/memory/AbstractBlob.java plugins/memory/MemoryNodeBuilder.java
Date Wed, 10 Oct 2012 15:36:25 GMT
Author: mduerig
Date: Wed Oct 10 15:36:25 2012
New Revision: 1396648

URL: http://svn.apache.org/viewvc?rev=1396648&view=rev
Log:
OAK-350: Unify PropertyState and CoreValue
- make Blob comparable
- remove unused imports
(Thanks Alex for the patch (OAK-371)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java?rev=1396648&r1=1396647&r2=1396648&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java Wed
Oct 10 15:36:25 2012
@@ -25,7 +25,7 @@ import javax.annotation.Nonnull;
 /**
  * Immutable representation of a binary value of finite length.
  */
-public interface Blob {
+public interface Blob extends Comparable<Blob> {
 
     /**
      * Returns a new stream for this value object. Multiple calls to this

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java?rev=1396648&r1=1396647&r2=1396648&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
Wed Oct 10 15:36:25 2012
@@ -26,6 +26,8 @@ import com.google.common.base.Optional;
 import com.google.common.hash.HashCode;
 import com.google.common.hash.Hasher;
 import com.google.common.hash.Hashing;
+import com.google.common.io.ByteStreams;
+
 import org.apache.jackrabbit.oak.api.Blob;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -106,4 +108,34 @@ public abstract class AbstractBlob imple
             log.warn("Error while closing stream", e);
         }
     }
+
+    @Override
+    public int compareTo(Blob o) {
+        return compare(getNewStream(), o.getNewStream()) ? 0 : 1;
+    }
+
+    private static boolean compare(InputStream in2, InputStream in1) {
+        try {
+            try {
+                byte[] buf1 = new byte[0x1000];
+                byte[] buf2 = new byte[0x1000];
+
+                while (true) {
+                    int read1 = ByteStreams.read(in1, buf1, 0, 0x1000);
+                    int read2 = ByteStreams.read(in2, buf2, 0, 0x1000);
+                    if (read1 != read2 || !Arrays.equals(buf1, buf2)) {
+                        return false;
+                    } else if (read1 != 0x1000) {
+                        return true;
+                    }
+                }
+            } finally {
+                in1.close();
+                in2.close();
+            }
+        } catch (IOException e) {
+            return false;
+        }
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1396648&r1=1396647&r2=1396648&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Wed Oct 10 15:36:25 2012
@@ -32,7 +32,6 @@ import com.google.common.collect.Immutab
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
@@ -42,7 +41,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
 
 /**
  * In-memory node state builder. The following two builder states are used



Mime
View raw message