thomasmueller commented on code in PR #2810:
URL: https://github.com/apache/jackrabbit-oak/pull/2810#discussion_r3014011769
##########
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:
I think we need to use a loop to skip correctly. Something like this:
```suggestion
long remaining = pos;
while (remaining > 0) {
long skipped = is.skip(remaining);
if (skipped <= 0) {
return -1;
}
remaining -= skipped;
}
```
Or use is.skipNBytes(pos) (Java 12+) which throws on short skip, or
IOUtils.skipFully() from Commons IO.
And then we should have a test case for this.
--
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]