thomasmueller commented on code in PR #1247:
URL: https://github.com/apache/jackrabbit-oak/pull/1247#discussion_r1435012817


##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/analysis/stream/NodeLineReader.java:
##########
@@ -0,0 +1,220 @@
+/*
+ * 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.jackrabbit.oak.index.indexer.document.flatfile.analysis.stream;
+
+import java.io.BufferedInputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.commons.json.JsonObject;
+import org.apache.jackrabbit.oak.commons.json.JsopReader;
+import org.apache.jackrabbit.oak.commons.json.JsopTokenizer;
+import 
org.apache.jackrabbit.oak.index.indexer.document.flatfile.analysis.stream.NodeProperty.PropertyValue;
+import 
org.apache.jackrabbit.oak.index.indexer.document.flatfile.analysis.stream.NodeProperty.ValueType;
+
+import net.jpountz.lz4.LZ4FrameInputStream;
+
+/**
+ * A reader for flat file stores.
+ */
+public class NodeLineReader implements NodeDataReader, Closeable {
+
+    private final LineNumberReader reader;
+    private final long fileSize;
+    private long lineCount;
+
+    private NodeLineReader(LineNumberReader reader, long fileSize) {
+        this.reader = reader;
+        this.fileSize = fileSize;
+    }
+
+    public static NodeLineReader open(String fileName) throws IOException {
+        long fileSize = new File(fileName).length();
+        InputStream fileIn = new BufferedInputStream(new 
FileInputStream(fileName));
+        try {
+            InputStream in;
+            if (fileName.endsWith(".lz4")) {
+                in = new LZ4FrameInputStream(fileIn);
+            } else {
+                in = fileIn;
+            }
+            LineNumberReader reader = new LineNumberReader(new 
InputStreamReader(in, StandardCharsets.UTF_8));
+            return new NodeLineReader(reader, fileSize);
+        } catch (IOException e) {
+            fileIn.close();
+            throw e;
+        }
+    }
+
+    public NodeData readNode() throws IOException {
+        String line = reader.readLine();
+        if (line == null) {
+            close();
+            return null;
+        }
+        if (++lineCount % 1000000 == 0) {
+            System.out.println(lineCount + " lines");

Review Comment:
   I don't think that's easy to add: we don't know how many lines. We could 
estimate the number of bytes we read so far.
   
   But again, it seems unnecessary currently.



-- 
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: dev-unsubscr...@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to