RESOLVED - BATCH-734: ItemReaders with Resource input should check for file during ItemStream#open

This commit is contained in:
robokaso
2008-07-21 13:13:44 +00:00
parent 05f94e5a15
commit 705bc284bf
9 changed files with 52 additions and 55 deletions

View File

@@ -214,7 +214,6 @@ public class FlatFileItemReader<T> extends AbstractBufferedItemReaderItemStream<
}
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource, "Input resource must not be null");
Assert.notNull(fieldSetMapper, "FieldSetMapper must not be null.");
}
@@ -231,6 +230,7 @@ public class FlatFileItemReader<T> extends AbstractBufferedItemReaderItemStream<
}
protected void doOpen() throws Exception {
Assert.notNull(resource, "Input resource must not be null");
Assert.state(resource.exists(), "Resource must exist: [" + resource + "]");
log.debug("Opening flat file for reading: " + resource);

View File

@@ -108,7 +108,6 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource, "The resource must be set");
Assert.notNull(fieldSetCreator, "A FieldSetCreator must be provided.");
}
@@ -237,6 +236,8 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I
*/
public void open(ExecutionContext executionContext) throws ItemStreamException {
Assert.notNull(resource, "The resource must be set");
if (!getOutputState().isInitialized()) {
doOpen(executionContext);
}

View File

@@ -16,7 +16,6 @@ import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.ResetFailedException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.batch.item.util.ExecutionContextUserSupport;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -34,8 +33,7 @@ import org.springframework.util.ClassUtils;
*
* @author Robert Kasanicky
*/
public class MultiResourceItemReader<T> extends ExecutionContextUserSupport implements ItemReader<T>, ItemStream,
InitializingBean {
public class MultiResourceItemReader<T> extends ExecutionContextUserSupport implements ItemReader<T>, ItemStream {
/**
* Unique object instance that marks resource boundaries in the item buffer
@@ -198,6 +196,8 @@ public class MultiResourceItemReader<T> extends ExecutionContextUserSupport impl
*/
public void open(ExecutionContext executionContext) throws ItemStreamException {
Assert.notEmpty(resources, "There must be at least one input resource");
Arrays.sort(resources, comparator);
index.open(executionContext);
@@ -233,10 +233,6 @@ public class MultiResourceItemReader<T> extends ExecutionContextUserSupport impl
this.delegate = delegate;
}
public void afterPropertiesSet() throws Exception {
Assert.notEmpty(resources, "There must be at least one input resource");
}
/**
* Set the boolean indicating whether or not state should be saved in the
* provided {@link ExecutionContext} during the {@link ItemStream} call to

View File

@@ -79,7 +79,6 @@ public class StaxEventItemReader<T> extends AbstractBufferedItemReaderItemStream
* @throws IllegalStateException if the Resource does not exist.
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource, "The Resource must not be null.");
Assert.notNull(eventReaderDeserializer, "The FragmentDeserializer must not be null.");
Assert.hasLength(fragmentRootElementName, "The FragmentRootElementName must not be null");
}
@@ -135,6 +134,7 @@ public class StaxEventItemReader<T> extends AbstractBufferedItemReaderItemStream
}
protected void doOpen() throws Exception {
Assert.notNull(resource, "The Resource must not be null.");
Assert.state(resource.exists(), "Input resource does not exist: [" + resource + "]");
inputStream = resource.getInputStream();

View File

@@ -240,7 +240,6 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource);
Assert.notNull(serializer);
}
@@ -250,6 +249,9 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements
* @see org.springframework.batch.item.ItemStream#open(ExecutionContext)
*/
public void open(ExecutionContext executionContext) {
Assert.notNull(resource, "The resource must be set");
long startAtPosition = 0;
// if restart data is provided, restart from provided offset