TheR1sing3un commented on code in PR #6625:
URL: https://github.com/apache/rocketmq/pull/6625#discussion_r1176213871


##########
tieredstore/src/main/java/org/apache/rocketmq/tieredstore/provider/inputstream/TieredFileSegmentInputStream.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.tieredstore.provider.inputstream;
+
+import org.apache.rocketmq.tieredstore.provider.TieredFileSegment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.List;
+public class TieredFileSegmentInputStream extends InputStream {
+
+    private final TieredFileSegment.FileSegmentType fileType;
+    protected final List<ByteBuffer> uploadBufferList;
+    private final int contentLength;
+
+    /**
+     * readPosition is the now position in the stream
+     */
+    protected int readPosition = 0;
+
+    /**
+     * curReadBufferIndex is the index of the buffer in uploadBufferList which 
is being read
+     */
+    protected int curReadBufferIndex = 0;
+    /**
+     * readPosInCurBuffer is the position in the buffer which is being read
+     */
+    protected int readPosInCurBuffer = 0;
+
+    /**
+     * curBuffer is the buffer which is being read, it is the same as 
uploadBufferList.get(curReadBufferIndex)
+     */
+    protected ByteBuffer curBuffer;
+
+    private int markReadPosition = -1;
+
+    private int markCurReadBufferIndex = -1;
+
+    private int markReadPosInCurBuffer = -1;
+
+
+    public TieredFileSegmentInputStream(TieredFileSegment.FileSegmentType 
fileType, List<ByteBuffer> uploadBufferList, int contentLength) {
+        this.fileType = fileType;
+        this.contentLength = contentLength;
+        this.uploadBufferList = uploadBufferList;
+        if (uploadBufferList.size() > 0) {
+            this.curBuffer = uploadBufferList.get(curReadBufferIndex);
+        }
+    }
+
+    @Override
+    public boolean markSupported() {
+        return true;
+    }
+
+    @Override
+    public synchronized void mark(int ignore) {
+        this.markReadPosition = readPosition;
+        this.markCurReadBufferIndex = curReadBufferIndex;
+        this.markReadPosInCurBuffer = readPosInCurBuffer;
+    }
+
+    @Override
+    public synchronized void reset() throws IOException {
+        if (this.markReadPosition == -1) {
+            throw new IOException("mark not set");
+        }
+        this.readPosition = markReadPosition;
+        this.curReadBufferIndex = markCurReadBufferIndex;
+        this.readPosInCurBuffer = markReadPosInCurBuffer;
+        if (this.curReadBufferIndex < uploadBufferList.size()) {
+            this.curBuffer = uploadBufferList.get(curReadBufferIndex);
+        }
+    }
+
+    @Override
+    public int available() {
+        return contentLength - readPosition;
+    }
+
+    public List<ByteBuffer> getUploadBufferList() {
+        return uploadBufferList;
+    }
+
+    public ByteBuffer getCodaBuffer() {
+        return null;
+    }
+
+    @Override
+    public int read() {

Review Comment:
   > Is there any efficient way to read batch from the InputStream?
   
   We can depend on `InputStream#read(byte[], int off, int len)` to read a 
batch data.
   <img width="675" alt="image" 
src="https://user-images.githubusercontent.com/87409330/234226008-0519b485-1cad-4730-b622-078d5e646e3b.png";>
   



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