diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemReader.java
index 5b530418e..d01b76b6d 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemReader.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemReader.java
@@ -41,9 +41,21 @@ import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
/**
+ * This class represents a {@link ItemReader}, that reads lines from text file,
+ * tokenizes them to structured tuples ({@link FieldSet}s) instances and maps
+ * the {@link FieldSet}s to domain objects. The location of the file is defined
+ * by the resource property. To separate the structure of the file,
+ * {@link LineTokenizer} is used to parse data obtained from the file.
+ *
+ * A {@link FlatFileItemReader} is not thread safe because it maintains state in
+ * the form of a {@link ResourceLineReader}. Be careful to configure a
+ * {@link FlatFileItemReader} using an appropriate factory or scope so that it
+ * is not shared between threads.
+ *
*
- * This class is a {@link FieldSetItemReader} that supports restart, skipping - * invalid lines and storing statistics. + * This class supports restart, skipping invalid lines and storing statistics. + * It can be configured to setup {@link FieldSet} column names from the file + * header, skip given number of lines at the beginning of the file. *
* * @author Waseem Malik @@ -86,13 +98,13 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In * Encapsulates the state of the input source. If it is null then we are * uninitialized. */ - protected LineReader reader; + private LineReader reader; /** * Initialize the reader if necessary. * @throws IllegalStateException if the resource cannot be opened */ - public void open() throws IllegalStateException { + public void open() throws StreamException { Assert.state(resource.exists(), "Resource must exist: [" + resource + "]"); @@ -123,6 +135,7 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In ((AbstractLineTokenizer) tokenizer).setNames(names); } } + mark(); } @@ -167,7 +180,7 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In } /** - * This method initialises the Input Source for Restart. It opens the input + * This method initialises the reader for Restart. It opens the input * file and position the buffer reader according to information provided by * the restart data * @@ -196,8 +209,8 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In } /** - * This method returns the restart Data for the input Source. It returns the - * current Line Count which can be used to re initialise the batch job in + * This method returns the execution attributes for the reader. It returns the + * current Line Count which can be used to reinitialise the batch job in * case of restart. */ public ExecutionAttributes getExecutionAttributes() { @@ -249,7 +262,7 @@ public class FlatFileItemReader implements ItemReader, Skippable, ItemStream, In } /** - * @return next line to be tokenized and mapped + * @return next line to be tokenized and mapped (possibly skips multiple lines). */ protected String readLine() { String line = nextLine(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderAdvancedTests.java similarity index 98% rename from spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderTests.java rename to spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderAdvancedTests.java index b3cc91fa5..5b2ee8012 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderAdvancedTests.java @@ -34,7 +34,7 @@ import org.springframework.core.io.Resource; * * @see FlatFileItemReaderBasicTests */ -public class FlatFileItemReaderTests extends TestCase { +public class FlatFileItemReaderAdvancedTests extends TestCase { // object under test private FlatFileItemReader reader = new FlatFileItemReader(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/BasicFlatFileItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderBasicTests.java similarity index 95% rename from spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/BasicFlatFileItemReaderTests.java rename to spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderBasicTests.java index fb4f27b6f..dd1c16c56 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/BasicFlatFileItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemReaderBasicTests.java @@ -36,10 +36,10 @@ import org.springframework.core.io.Resource; /** * Tests for {@link FlatFileItemReader} - the fundamental item reading functionality. * - * @see FlatFileItemReaderTests + * @see FlatFileItemReaderAdvancedTests * @author Dave Syer */ -public class BasicFlatFileItemReaderTests extends TestCase { +public class FlatFileItemReaderBasicTests extends TestCase { // object under test private FlatFileItemReader itemReader = new FlatFileItemReader();