1 /* 2 * Copyright (C) 2009 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.io; 16 17 import com.google.common.annotations.GwtIncompatible; 18 import com.google.common.annotations.J2ktIncompatible; 19 import com.google.errorprone.annotations.CanIgnoreReturnValue; 20 import java.io.IOException; 21 import org.checkerframework.checker.nullness.qual.Nullable; 22 23 /** 24 * A callback to be used with the streaming {@code readLines} methods. 25 * 26 * <p>{@link #processLine} will be called for each line that is read, and should return {@code 27 * false} when you want to stop processing. 28 * 29 * @author Miles Barr 30 * @since 1.0 31 */ 32 @J2ktIncompatible 33 @GwtIncompatible 34 @ElementTypesAreNonnullByDefault 35 public interface LineProcessor<T extends @Nullable Object> { 36 37 /** 38 * This method will be called once for each line. 39 * 40 * @param line the line read from the input, without delimiter 41 * @return true to continue processing, false to stop 42 */ 43 @CanIgnoreReturnValue // some uses know that their processor never returns false processLine(String line)44 boolean processLine(String line) throws IOException; 45 46 /** Return the result of processing all the lines. */ 47 @ParametricNullness getResult()48 T getResult(); 49 } 50