jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1149603 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Fri, 22 Jul 2011 13:39:15 GMT
Author: mduerig
Date: Fri Jul 22 13:39:14 2011
New Revision: 1149603

URL: http://svn.apache.org/viewvc?rev=1149603&view=rev
Log:
spi2microkernel (WIP)
- Base64 encode small binaries

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1149603&r1=1149602&r2=1149603&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Fri Jul 22 13:39:14 2011
@@ -25,8 +25,12 @@ import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
+import org.apache.jackrabbit.util.Base64;
 
 import javax.jcr.RepositoryException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -156,7 +160,14 @@ public final class Values {
             }
 
             public QValue create(String value) throws RepositoryException {
-                return FACTORY.create(value, BINARY);
+                try {
+                    ByteArrayOutputStream os = new ByteArrayOutputStream();
+                    Base64.decode(value, os);
+                    return FACTORY.create(os.toByteArray());
+                }
+                catch (IOException e) {
+                    throw new RepositoryException(e); 
+                }
             }
         };
         put(TYPES[BINARY], valueFactory);
@@ -302,7 +313,14 @@ public final class Values {
                     }
                 }
                 else {
-                    return typeEncode(type, JsonBuilder.escape(value.getString()));
+                    try {
+                        StringWriter sw = new StringWriter();
+                        Base64.encode(value.getStream(), sw);
+                        return typeEncode(type, JsonBuilder.escape(sw.toString()));
+                    }
+                    catch (IOException e) {
+                        throw new RepositoryException(e); 
+                    }
                 }
 
             case REFERENCE:

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1149603&r1=1149602&r2=1149603&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Fri Jul 22 13:39:14 2011
@@ -582,6 +582,14 @@ public class RepositoryTest {
     }
 
     @Test
+    public void addSmallBinaryProperty() throws RepositoryException, IOException {
+        Node parentNode = getNode(testPath);
+        InputStream is = new NumberStream(1234);
+        Binary bin = getSession().getValueFactory().createBinary(is);
+        addProperty(parentNode, "bigBinary", getSession().getValueFactory().createValue(bin));
+    }
+
+    @Test
     public void addBigBinaryProperty() throws RepositoryException, IOException {
         Node parentNode = getNode(testPath);
         InputStream is = new NumberStream(123456);



Mime
View raw message