com.swirlds.config.extensions.export.ConfigExport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swirlds-config-extensions Show documentation
Show all versions of swirlds-config-extensions Show documentation
Swirlds is a software platform designed to build fully-distributed applications that harness the power of the cloud without servers. Now you can develop applications with fairness in decision making, speed, trust and reliability, at a fraction of the cost of traditional server-based platforms.
/*
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC
*
* Licensed 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 com.swirlds.config.extensions.export;
import com.swirlds.config.api.Configuration;
import com.swirlds.config.extensions.reflection.ConfigReflectionUtils;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.RecordComponent;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* Class that provides functionallity to print information about the config.
*/
public final class ConfigExport {
private static final String ERROR_CONFIGURATION_IS_NULL = "configuration should not be null";
private static final String ERROR_PRINT_STREAM_IS_NULL = "printStream should not be null";
private static final String ERROR_BUILDER_IS_NULL = "builder should not be null";
private static final String ERROR_LINE_CONSUMER_IS_NULL = "lineConsumer should not be null";
private ConfigExport() {}
/**
* Provides information about the config with 1 line per config property to the consumer. The format of one line
* looks like this:
*
* name, value
*
*
* @param configuration the configuration
* @param lineConsumer the line consumer
*/
public static void printConfig(
@NonNull final Configuration configuration, @NonNull final Consumer lineConsumer) {
Objects.requireNonNull(configuration, ERROR_CONFIGURATION_IS_NULL);
Objects.requireNonNull(lineConsumer, ERROR_LINE_CONSUMER_IS_NULL);
// Properties defined in record configs, including values overridden by configured sources
final Map recordProperties = getPropertiesForConfigDataRecords(configuration);
// Properties defined in property file but do not exist in record configs
final Map nonRecordProperties = new HashMap<>();
configuration
.getPropertyNames()
.filter(name -> !recordProperties.containsKey(name))
.forEach(name -> nonRecordProperties.put(name, configuration.getValue(name)));
final Set