All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.xpack.security.support.FileLineParser Maven / Gradle / Ivy

There is a newer version: 8.16.1
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

package org.elasticsearch.xpack.security.support;

import org.apache.logging.log4j.util.Strings;
import org.elasticsearch.common.CheckedBiConsumer;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class FileLineParser {
    public static void parse(Path path, CheckedBiConsumer lineParser) throws IOException {
        final List lines = Files.readAllLines(path, StandardCharsets.UTF_8);

        int lineNumber = 0;
        for (String line : lines) {
            lineNumber++;
            if (line.startsWith("#") || Strings.isBlank(line)) { // comment or blank
                continue;
            }

            lineParser.accept(lineNumber, line);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy