View Javadoc

1   /*
2    * Copyright 2006-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.batch.item;
17  
18  /**
19   * <p>
20   * A specialisation of {@link ItemReader} that allows the user to look ahead
21   * into the stream of items. This is useful, for instance, when reading flat
22   * file data that contains record separator lines which are actually part of the
23   * next record.
24   * </p>
25   * 
26   * <p>
27   * The detailed contract for {@link #peek()} has to be defined by the
28   * implementation because there is no general way to define it in a concurrent
29   * environment. The definition of "the next read()" operation is tenuous if
30   * multiple clients are reading concurrently, and the ability to peek implies
31   * that some state is likely to be stored, so implementations of
32   * {@link PeekableItemReader} may well be restricted to single threaded use.
33   * </p>
34   * 
35   * @author Dave Syer
36   * 
37   */
38  public interface PeekableItemReader<T> extends ItemReader<T> {
39  
40  	/**
41  	 * Get the next item that would be returned by {@link #read()}, without
42  	 * affecting the result of {@link #read()}.
43  	 * 
44  	 * @return the next item
45  	 * @throws Exception if there is a problem
46  	 */
47  	T peek() throws Exception, UnexpectedInputException, ParseException;
48  
49  }