You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "stefan-egli (via GitHub)" <gi...@apache.org> on 2023/07/13 09:38:45 UTC

[GitHub] [jackrabbit-oak] stefan-egli commented on a diff in pull request #1021: OAK-10347 : Adding small util class for exporting a tree as flat file

stefan-egli commented on code in PR #1021:
URL: https://github.com/apache/jackrabbit-oak/pull/1021#discussion_r1262300881


##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/SimpleFlatFileUtil.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.function.Predicate;
+
+import org.apache.jackrabbit.oak.index.indexer.document.NodeStateEntry;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This util class can be used to export a tree (eg entire repository) to a flat
+ * file, without index dependency/involvement.
+ */
+public class SimpleFlatFileUtil {
+
+    private static final Logger log = LoggerFactory.getLogger(SimpleFlatFileUtil.class);
+
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
+    private final FileWriter fw;
+    private final BufferedWriter bw;
+    private final ArrayList<StateInBytesHolder> entryBatch = new ArrayList<>();
+    private final Predicate<String> pathPredicate = path -> true;
+    private final NodeStateEntryWriter entryWriter;
+    private long totalLines = 0;
+
+    private SimpleFlatFileUtil(File f) throws IOException {
+        // blobStore is only used for deserialization - so pass null here:
+        entryWriter = new NodeStateEntryWriter(null);
+        fw = new FileWriter(f);
+        bw = new BufferedWriter(fw);
+    }
+
+    public static void createFlatFileFor(NodeState ns, File f) throws IOException {
+        final SimpleFlatFileUtil h = new SimpleFlatFileUtil(f);
+        log.info("createFlatFileFor : writing to {}", f.getCanonicalPath());
+        h.addEntryAndTraverseChildren(ns);
+        h.close();

Review Comment:
   +1, I'll fix that



-- 
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-unsubscribe@jackrabbit.apache.org

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