You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by th...@apache.org on 2007/08/28 16:14:18 UTC

svn commit: r570439 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value: BLOBFileValue.java InternalValue.java

Author: thomasm
Date: Tue Aug 28 07:14:17 2007
New Revision: 570439

URL: http://svn.apache.org/viewvc?rev=570439&view=rev
Log:
JCR-926: global data store: re-added useful methods

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=570439&r1=570438&r2=570439&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java Tue Aug 28 07:14:17 2007
@@ -285,6 +285,51 @@
         }
     }
 
+    /**
+     * Spools the contents of this <code>BLOBFileValue</code> to the given
+     * output stream.
+     *
+     * @param out output stream
+     * @throws RepositoryException if the input stream for this
+     *                             <code>BLOBFileValue</code> could not be obtained
+     * @throws IOException         if an error occurs while while spooling
+     */
+    public void spool(OutputStream out) throws RepositoryException, IOException {
+        InputStream in;
+        if (file != null) {
+            // this instance is backed by a 'real' file
+            try {
+                in = new FileInputStream(file);
+            } catch (FileNotFoundException fnfe) {
+                throw new RepositoryException("file backing binary value not found",
+                        fnfe);
+            }
+        } else if (fsResource != null) {
+            // this instance is backed by a resource in the virtual file system
+            try {
+                in = fsResource.getInputStream();
+            } catch (FileSystemException fse) {
+                throw new RepositoryException(fsResource.getPath()
+                        + ": the specified resource does not exist", fse);
+            }
+        } else {
+            // this instance is backed by an in-memory buffer
+            in = new ByteArrayInputStream(buffer);
+        }
+        try {
+            byte[] buffer = new byte[0x2000];
+            int read;
+            while ((read = in.read(buffer)) > 0) {
+                out.write(buffer, 0, read);
+            }
+        } finally {
+            try {
+                in.close();
+            } catch (IOException ignore) {
+            }
+        }
+    }
+
     //-------------------------------------------< java.lang.Object overrides >
     /**
      * Returns a string representation of this <code>BLOBFileValue</code>

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=570439&r1=570438&r2=570439&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java Tue Aug 28 07:14:17 2007
@@ -263,6 +263,18 @@
         }
         return ret;
     }
+    
+    /**
+     * @param values
+     * @return the created value
+     */
+    public static InternalValue[] create(String[] values) {
+        InternalValue[] ret = new InternalValue[values.length];
+        for (int i = 0; i < values.length; i++) {
+            ret[i] = new InternalValue(values[i]);
+        }
+        return ret;
+    }    
 
     /**
      * @param value