jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1242403 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: store/BinaryBinding.java store/Binding.java store/MongoPersistenceManager.java util/IOUtils.java
Date Thu, 09 Feb 2012 17:14:18 GMT
Author: stefan
Date: Thu Feb  9 17:14:18 2012
New Revision: 1242403

URL: http://svn.apache.org/viewvc?rev=1242403&view=rev
Log:
serialize byte[] values

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java?rev=1242403&r1=1242402&r2=1242403&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/BinaryBinding.java
Thu Feb  9 17:14:18 2012
@@ -43,6 +43,7 @@ public class BinaryBinding implements Bi
         in = null;
     }
 
+    @Override
     public void write(String key, String value) throws Exception {
         if (out == null) {
             throw new IllegalStateException("no OutputStream provided");
@@ -50,6 +51,15 @@ public class BinaryBinding implements Bi
         IOUtils.writeString(out, value);
     }
 
+    @Override
+    public void write(String key, byte[] value) throws Exception {
+        if (out == null) {
+            throw new IllegalStateException("no OutputStream provided");
+        }
+        IOUtils.writeBytes(out, value);
+    }
+
+    @Override
     public void write(String key, long value) throws Exception {
         if (out == null) {
             throw new IllegalStateException("no OutputStream provided");
@@ -57,6 +67,7 @@ public class BinaryBinding implements Bi
         IOUtils.writeVarLong(out, value);
     }
 
+    @Override
     public void write(String key, int value) throws Exception {
         if (out == null) {
             throw new IllegalStateException("no OutputStream provided");
@@ -64,6 +75,7 @@ public class BinaryBinding implements Bi
         IOUtils.writeVarInt(out, value);
     }
 
+    @Override
     public void write(String key, int count, Iterator<KeyValuePair> iterator) throws
Exception {
         if (out == null) {
             throw new IllegalStateException("no OutputStream provided");
@@ -76,6 +88,7 @@ public class BinaryBinding implements Bi
         }
     }
 
+    @Override
     public String readStringValue(String key) throws Exception {
         if (in == null) {
             throw new IllegalStateException("no InputStream provided");
@@ -83,6 +96,15 @@ public class BinaryBinding implements Bi
         return IOUtils.readString(in);
     }
 
+    @Override
+    public byte[] readBytesValue(String key) throws Exception {
+        if (in == null) {
+            throw new IllegalStateException("no InputStream provided");
+        }
+        return IOUtils.readBytes(in);
+    }
+
+    @Override
     public long readLongValue(String key) throws Exception {
         if (in == null) {
             throw new IllegalStateException("no InputStream provided");
@@ -90,6 +112,7 @@ public class BinaryBinding implements Bi
         return IOUtils.readVarLong(in);
     }
 
+    @Override
     public int readIntValue(String key) throws Exception {
         if (in == null) {
             throw new IllegalStateException("no InputStream provided");
@@ -97,6 +120,7 @@ public class BinaryBinding implements Bi
         return IOUtils.readVarInt(in);
     }
 
+    @Override
     public Iterator<KeyValuePair> read(String key) throws Exception {
         if (in == null) {
             throw new IllegalStateException("no InputStream provided");

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java?rev=1242403&r1=1242402&r2=1242403&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
Thu Feb  9 17:14:18 2012
@@ -24,11 +24,13 @@ import java.util.Iterator;
 public interface Binding {
     
     void write(String key, String value) throws Exception;
+    void write(String key, byte[] value) throws Exception;
     void write(String key, long value) throws Exception;
     void write(String key, int value) throws Exception;
     void write(String key, int count, Iterator<KeyValuePair> iterator) throws Exception;
     
     String readStringValue(String key) throws Exception;
+    byte[] readBytesValue(String key) throws Exception;
     long readLongValue(String key) throws Exception;
     int readIntValue(String key) throws Exception;
     Iterator<KeyValuePair> read(String key) throws Exception;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java?rev=1242403&r1=1242402&r2=1242403&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
Thu Feb  9 17:14:18 2012
@@ -365,6 +365,11 @@ public class MongoPersistenceManager ext
         }
 
         @Override
+        public void write(String key, byte[] value) throws Exception {
+            obj.append(encodeName(key), StringUtils.convertBytesToHex(value));
+        }
+
+        @Override
         public void write(String key, long value) throws Exception {
             obj.append(encodeName(key), value);
         }
@@ -390,6 +395,11 @@ public class MongoPersistenceManager ext
         }
 
         @Override
+        public byte[] readBytesValue(String key) throws Exception {
+            return StringUtils.convertHexToBytes(obj.getString(encodeName(key)));
+        }
+
+        @Override
         public long readLongValue(String key) throws Exception {
             return obj.getLong(encodeName(key));
         }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java?rev=1242403&r1=1242402&r2=1242403&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/IOUtils.java
Thu Feb  9 17:14:18 2012
@@ -81,9 +81,7 @@ public class IOUtils {
      * @param s the string (maximum length about 2 GB)
      */
     public static void writeString(OutputStream out, String s) throws IOException {
-        byte[] data = s.getBytes("UTF-8");
-        writeVarInt(out, data.length);
-        out.write(data);
+        writeBytes(out, s.getBytes("UTF-8"));
     }
 
     /**
@@ -94,6 +92,29 @@ public class IOUtils {
      * @return the string
      */
     public static String readString(InputStream in) throws IOException {
+        return new String(readBytes(in), "UTF-8");
+    }
+
+    /**
+     * Write a byte array. This will first write the length as 4 bytes, and then
+     * the actual bytes.
+     *
+     * @param out the data output stream
+     * @param data the byte array
+     */
+    public static void writeBytes(OutputStream out, byte[] data) throws IOException {
+        writeVarInt(out, data.length);
+        out.write(data);
+    }
+
+    /**
+     * Read a byte array. This will first read the length as 4 bytes, and then 
+     * the actual bytes.
+     *
+     * @param in the data input stream
+     * @return the bytes
+     */
+    public static byte[] readBytes(InputStream in) throws IOException {
         int len = readVarInt(in);
         byte[] data = new byte[len];
         for (int pos = 0; pos < len;) {
@@ -103,7 +124,7 @@ public class IOUtils {
             }
             pos += l;
         }
-        return new String(data, "UTF-8");
+        return data;
     }
 
     /**



Mime
View raw message