1 /*
2 * Copyright 2006-2007 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
17 package org.springframework.batch.item.file.separator;
18
19 import java.io.BufferedReader;
20
21 /**
22 * Policy for text file-based input sources to determine the end of a record,
23 * e.g. a record might be a single line, or it might be multiple lines
24 * terminated by a semicolon.
25 *
26 * @author Dave Syer
27 *
28 */
29 public interface RecordSeparatorPolicy {
30
31 /**
32 * Signal the end of a record based on the content of the current record.
33 * During the course of processing, each time this method returns false,
34 * the next line read is appended onto it (building the record). The input
35 * is what you would expect from {@link BufferedReader#readLine()} - i.e.
36 * no line separator character at the end. But it might have line separators
37 * embedded in it.
38 *
39 * @param record a String without a newline character at the end.
40 * @return true if this line is a complete record.
41 */
42 boolean isEndOfRecord(String record);
43
44 /**
45 * Give the policy a chance to post-process a complete record, e.g. remove a
46 * suffix.
47 *
48 * @param record the complete record.
49 * @return a modified version of the record if desired.
50 */
51 String postProcess(String record);
52
53 /**
54 * Pre-process a record before another line is appended, in the case of a
55 * multi-line record. Can be used to remove a prefix or line-continuation
56 * marker. If a record is a single line this callback is not used (but
57 * {@link #postProcess(String)} will be).
58 *
59 * @param record the current record.
60 * @return the line as it should be appended to a record.
61 */
62 String preProcess(String record);
63
64 }