reschke commented on code in PR #2810:
URL: https://github.com/apache/jackrabbit-oak/pull/2810#discussion_r3014029315


##########
oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/MigrationFactory.java:
##########
@@ -125,4 +125,91 @@ private List<CommitHook> loadCommitHooks() {
         return 
Collections.unmodifiableList(ListUtils.toList(loader.iterator()));
     }
 
+    /**
+     * Wraps An Oak BlobStore around a Jackrabbit Datastore
+     */
+    private static class ToJackrabbitDataStoreDelegatingBlobStore implements 
BlobStore {
+
+        private org.apache.jackrabbit.core.data.DataStore delegate;
+
+        public ToJackrabbitDataStoreDelegatingBlobStore(
+                org.apache.jackrabbit.core.data.DataStore delegate) {
+            this.delegate = delegate;
+        }
+
+        @Override
+        public String writeBlob(InputStream inputStream) throws IOException {
+            try {
+                org.apache.jackrabbit.core.data.DataRecord record = 
delegate.addRecord(inputStream);
+                return record.getIdentifier().toString();
+            } catch (org.apache.jackrabbit.core.data.DataStoreException ex) {
+                throw new IOException("Failed to write blob", ex);
+            }
+        }
+
+        @Override
+        public String writeBlob(InputStream inputStream, BlobOptions options) 
throws IOException {
+            try {
+                org.apache.jackrabbit.core.data.DataRecord record = 
delegate.addRecord(inputStream);
+                return record.getIdentifier().toString();
+            } catch (org.apache.jackrabbit.core.data.DataStoreException ex) {
+                throw new IOException("Failed to write blob", ex);
+            }
+        }
+
+        @Override
+        public int readBlob(String blobId, long pos, byte[] buff, int off, int 
length)
+                throws IOException {
+
+            try (InputStream is = getInputStream(blobId)) {
+
+                if (pos > 0) {
+                    long skipped = is.skip(pos);
+                    if (skipped < pos) {
+                        return -1;
+                    }
+                }
+
+                return is.read(buff, off, length);

Review Comment:
   > And then we should have a test case for this.
   
   I'll have a look.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to