001/*
002 * Copyright 2006-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.springframework.batch.item;
017
018import org.springframework.lang.Nullable;
019
020/**
021 * <p>
022 * A specialisation of {@link ItemReader} that allows the user to look ahead
023 * into the stream of items. This is useful, for instance, when reading flat
024 * file data that contains record separator lines which are actually part of the
025 * next record.
026 * </p>
027 * 
028 * <p>
029 * The detailed contract for {@link #peek()} has to be defined by the
030 * implementation because there is no general way to define it in a concurrent
031 * environment. The definition of "the next read()" operation is tenuous if
032 * multiple clients are reading concurrently, and the ability to peek implies
033 * that some state is likely to be stored, so implementations of
034 * {@link PeekableItemReader} may well be restricted to single threaded use.
035 * </p>
036 * 
037 * @author Dave Syer
038 * @author Mahmoud Ben Hassine
039 * 
040 */
041public interface PeekableItemReader<T> extends ItemReader<T> {
042
043        /**
044         * Get the next item that would be returned by {@link #read()}, without
045         * affecting the result of {@link #read()}.
046         * 
047         * @return the next item or {@code null} if the data source is exhausted
048         * @throws Exception if there is a problem
049         */
050        @Nullable
051        T peek() throws Exception, UnexpectedInputException, ParseException;
052
053}