zymap commented on code in PR #15063:
URL: https://github.com/apache/pulsar/pull/15063#discussion_r847853847


##########
tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlockAwareSegmentInputStreamImpl.java:
##########
@@ -143,6 +191,41 @@ private int readEntries() throws IOException {
         }
     }
 
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        if (len == 0) {
+            return 0;
+        }
+
+        int offset = off;
+        int readLen = len;
+        int readBytes = 0;
+        // reading header
+        if (dataBlockHeaderStream.available() > 0) {
+            int read = dataBlockHeaderStream.read(b, off, len);
+            offset += read;
+            readLen -= readLen;
+            readBytes += read;
+            bytesReadOffset += read;
+        }
+        if (readLen == 0) {
+            return readBytes;
+        }
+
+        // reading ledger entries
+        if (bytesReadOffset < blockSize) {
+            byte[] readEntries = readEntries(readLen);
+            for (int i = 0; i < readEntries.length; i++) {
+                b[offset + i] = readEntries[i];
+                readBytes++;
+            }
+            return readBytes;
+        }
+
+        // reached end
+        return -1;

Review Comment:
   Yes. Here has a test:  
https://github.com/apache/pulsar/pull/15063/files#diff-1f2edfe47e5f4f0d8b1634a21eeaccf78eb36d05c55d1c02f20f146247926defR681



-- 
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