001/*
002 * Configurate
003 * Copyright (C) zml and Configurate contributors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.spongepowered.configurate.loader;
018
019import com.google.errorprone.annotations.Immutable;
020import org.checkerframework.checker.nullness.qual.Nullable;
021
022import java.io.BufferedReader;
023import java.io.IOException;
024import java.util.stream.Stream;
025
026/**
027 * Extracts comments from a buffered reader or collection of lines.
028 *
029 * @since 4.0.0
030 */
031@Immutable
032public interface CommentHandler {
033
034    /**
035     * Defines the handlers behaviour for reading comments.
036     *
037     * @param reader reader to get input from
038     * @return an extracted comment, if any
039     * @throws IOException if any IO error occurs in the process
040     * @since 4.0.0
041     */
042    @Nullable String extractHeader(BufferedReader reader) throws IOException;
043
044    /**
045     * Converts the specified lines into a comment.
046     *
047     * @param lines lines to make a comment
048     * @return transformed lines as a stream
049     * @since 4.0.0
050     */
051    Stream<String> toComment(Stream<String> lines);
052
053}