jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1577450 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
Date Fri, 14 Mar 2014 08:43:22 GMT
Author: chetanm
Date: Fri Mar 14 08:43:21 2014
New Revision: 1577450

URL: http://svn.apache.org/r1577450
Log:
OAK-805 - Support for existing Jackrabbit 2.x DataStores

Minor change. Using ByteStream util to skip inputstream and proper closing of InputStreams

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java?rev=1577450&r1=1577449&r2=1577450&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
Fri Mar 14 08:43:21 2014
@@ -33,13 +33,14 @@ import javax.jcr.RepositoryException;
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterators;
+import com.google.common.io.ByteStreams;
+import com.google.common.io.Closeables;
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataRecord;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.data.DataStoreException;
 import org.apache.jackrabbit.core.data.MultiDataStoreAware;
-import org.apache.jackrabbit.oak.commons.IOUtils;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
 
@@ -120,11 +121,18 @@ public class DataStoreBlobStore implemen
     //~-------------------------------------------< BlobStore >
 
     @Override
-    public String writeBlob(InputStream in) throws IOException {
+    public String writeBlob(InputStream stream) throws IOException {
+        boolean threw = true;
         try {
-            return writeStream(in).getIdentifier().toString();
+            String id = writeStream(stream).getIdentifier().toString();
+            threw = false;
+            return id;
         } catch (DataStoreException e) {
             throw new IOException(e);
+        } finally {
+            //DataStore does not closes the stream internally
+            //So close the stream explicitly
+            Closeables.close(stream, threw);
         }
     }
 
@@ -133,19 +141,15 @@ public class DataStoreBlobStore implemen
         //This is inefficient as repeated calls for same blobId would involve opening new
Stream
         //instead clients should directly access the stream from DataRecord by special casing
for
         //BlobStore which implements DataStore
-        InputStream in = getStream(blobId);
+        InputStream stream = getStream(blobId);
+        boolean threw = true;
         try {
-            long skip = pos;
-            while (skip > 0) {
-                long skipped = in.skip(skip);
-                if (skipped <= 0) {
-                    return -1;
-                }
-                skip -= skipped;
-            }
-            return IOUtils.readFully(in, buff,off,length);
+            ByteStreams.skipFully(stream, pos);
+            int readCount = stream.read(buff, off, length);
+            threw = false;
+            return readCount;
         } finally {
-            in.close();
+            Closeables.close(stream, threw);
         }
     }
 



Mime
View raw message