diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java index 71b11f5eb..3577f53e9 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java @@ -25,7 +25,6 @@ import java.nio.channels.FileChannel; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import org.springframework.batch.item.ClearFailedException; @@ -93,12 +92,12 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I private int bufferSize = OutputState.DEFAULT_BUFFER_SIZE; - private List lineBuffer = new ArrayList(); + private List lineBuffer = new ArrayList(); - private List headerLines = new ArrayList(); + private List headerLines = new ArrayList(); private String lineSeparator = DEFAULT_LINE_SEPARATOR; - + public FlatFileItemWriter() { setName(ClassUtils.getShortName(FlatFileItemWriter.class)); } @@ -207,15 +206,15 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I * * @param data Object (a String or Object that can be converted) to be * written to output stream - * @throws Exception if the transformer or file output fail, WriterNotOpenException - * if the writer has not been initialized. + * @throws Exception if the transformer or file output fail, + * WriterNotOpenException if the writer has not been initialized. */ public void write(Object data) throws Exception { - if(getOutputState().isInitialized()){ + if (getOutputState().isInitialized()) { FieldSet fieldSet = fieldSetCreator.mapItem(data); lineBuffer.add(lineAggregator.aggregate(fieldSet) + lineSeparator); } - else{ + else { throw new WriterNotOpenException("Writer must be open before it can be written to"); } } @@ -231,19 +230,19 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I } /** - * Initialize the reader. This method may be called multiple times before close is - * called. + * Initialize the reader. This method may be called multiple times before + * close is called. * * @see ItemStream#open(ExecutionContext) */ public void open(ExecutionContext executionContext) throws ItemStreamException { - if(!getOutputState().isInitialized()){ + if (!getOutputState().isInitialized()) { doOpen(executionContext); } } - - private void doOpen(ExecutionContext executionContext){ + + private void doOpen(ExecutionContext executionContext) { OutputState outputState = getOutputState(); if (executionContext.containsKey(getKey(RESTART_DATA_NAME))) { outputState.restoreFrom(executionContext); @@ -255,8 +254,7 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I throw new ItemStreamException("Failed to initialize writer", ioe); } if (outputState.lastMarkedByteOffsetPosition == 0) { - for (Iterator iterator = headerLines.iterator(); iterator.hasNext();) { - String line = (String) iterator.next(); + for (String line : headerLines) { lineBuffer.add(line + lineSeparator); } } @@ -288,8 +286,7 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I public void flush() throws FlushFailedException { OutputState state = getOutputState(); - for (Iterator iterator = lineBuffer.listIterator(); iterator.hasNext();) { - String line = (String) iterator.next(); + for (String line : lineBuffer) { try { state.write(line); } @@ -350,7 +347,7 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I long restartCount = 0; boolean shouldDeleteIfExists = true; - + boolean initialized = false; /** @@ -460,8 +457,7 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I * @throws IOException */ private void initializeBufferedWriter() throws IOException { - - + File file = resource.getFile(); FileUtils.setUpOutputFile(file, restarted, shouldDeleteIfExists); @@ -478,7 +474,7 @@ public class FlatFileItemWriter extends ExecutionContextUserSupport implements I initialized = true; linesWritten = 0; } - + public boolean isInitialized() { return initialized; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java index 602a89478..c75ceadb1 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemReader.java @@ -48,22 +48,20 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme private MultiResourceIndex index = new MultiResourceIndex(); - private List itemBuffer = new ArrayList(); + private List itemBuffer = new ArrayList(); - private ListIterator itemBufferIterator = null; + private ListIterator itemBufferIterator = null; private boolean shouldReadBuffer = false; private boolean saveState = false; - private Comparator comparator = new Comparator() { + private Comparator comparator = new Comparator() { /** * Compares resource filenames. */ - public int compare(Object o1, Object o2) { - Resource r1 = (Resource) o1; - Resource r2 = (Resource) o2; + public int compare(Resource r1, Resource r2) { return r1.getFilename().compareTo(r2.getFilename()); } @@ -253,7 +251,7 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme * @param comparator used to order the injected resources, by default * compares {@link Resource#getFilename()} values. */ - public void setComparator(Comparator comparator) { + public void setComparator(Comparator comparator) { this.comparator = comparator; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java index 81ee85b4e..20f28ddbc 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapper.java @@ -42,18 +42,19 @@ import org.springframework.validation.ObjectError; /** * {@link FieldSetMapper} implementation based on bean property paths. The - * {@link DefaultFieldSet} to be mapped should have field name meta data corresponding - * to bean property paths in a prototype instance of the desired type. The - * prototype instance is initialized either by referring to to object by bean - * name in the enclosing BeanFactory, or by providing a class to instantiate - * reflectively.
+ * {@link DefaultFieldSet} to be mapped should have field name meta data + * corresponding to bean property paths in a prototype instance of the desired + * type. The prototype instance is initialized either by referring to to object + * by bean name in the enclosing BeanFactory, or by providing a class to + * instantiate reflectively.
* * Nested property paths, including indexed properties in maps and collections, - * can be referenced by the {@link DefaultFieldSet} names. They will be converted to - * nested bean properties inside the prototype. The {@link DefaultFieldSet} and the - * prototype are thus tightly coupled by the fields that are available and those - * that can be initialized. If some of the nested properties are optional (e.g. - * collection members) they need to be removed by a post processor.
+ * can be referenced by the {@link DefaultFieldSet} names. They will be + * converted to nested bean properties inside the prototype. The + * {@link DefaultFieldSet} and the prototype are thus tightly coupled by the + * fields that are available and those that can be initialized. If some of the + * nested properties are optional (e.g. collection members) they need to be + * removed by a post processor.
* * Property name matching is "fuzzy" in the sense that it tolerates close * matches, as long as the match is unique. For instance: @@ -76,11 +77,12 @@ import org.springframework.validation.ObjectError; * @author Dave Syer * */ -public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar implements FieldSetMapper, BeanFactoryAware, InitializingBean { +public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar implements FieldSetMapper, + BeanFactoryAware, InitializingBean { private String name; - private Class type; + private Class type; private BeanFactory beanFactory; @@ -91,7 +93,9 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im /* * (non-Javadoc) * - * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory) + * @see + * org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org + * .springframework.beans.factory.BeanFactory) */ public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; @@ -140,27 +144,27 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im } /** - * Map the {@link DefaultFieldSet} to an object retrieved from the enclosing Spring - * context, or to a new instance of the required type if no prototype is - * available. + * Map the {@link DefaultFieldSet} to an object retrieved from the enclosing + * Spring context, or to a new instance of the required type if no prototype + * is available. * - * @throws NotWritablePropertyException if the {@link DefaultFieldSet} contains a - * field that cannot be mapped to a bean property. + * @throws NotWritablePropertyException if the {@link DefaultFieldSet} + * contains a field that cannot be mapped to a bean property. * @throws BindingException if there is a type conversion or other error (if * the {@link DataBinder} from {@link #createBinder(Object)} has errors * after binding). * * @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapLine(org.springframework.batch.item.file.mapping.FieldSet) */ + @SuppressWarnings("unchecked") public Object mapLine(FieldSet fs) { Object copy = getBean(); DataBinder binder = createBinder(copy); binder.bind(new MutablePropertyValues(getBeanProperties(copy, fs.getProperties()))); if (binder.getBindingResult().hasErrors()) { - List errors = binder.getBindingResult().getAllErrors(); - List messages = new ArrayList(errors.size()); - for (Iterator iterator = errors.iterator(); iterator.hasNext();) { - ObjectError error = (ObjectError) iterator.next(); + List errors = binder.getBindingResult().getAllErrors(); + List messages = new ArrayList(errors.size()); + for (ObjectError error : errors) { messages.add(error.getDefaultMessage()); } throw new BindingException("" + messages); @@ -189,9 +193,8 @@ public class BeanWrapperFieldSetMapper extends DefaultPropertyEditorRegistrar im /** * Initialize a new binder instance. This hook allows customization of - * binder settings such as the - * {@link DataBinder#initDirectFieldAccess() direct field access}. Called - * by {@link #createBinder(Object)}. + * binder settings such as the {@link DataBinder#initDirectFieldAccess() + * direct field access}. Called by {@link #createBinder(Object)}. *

* Note that registration of custom property editors should be done in * {@link #registerCustomEditors(PropertyEditorRegistry)}, not here! This diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultFieldSet.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultFieldSet.java index dac1632f1..59d64155b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultFieldSet.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/DefaultFieldSet.java @@ -44,7 +44,7 @@ public class DefaultFieldSet implements FieldSet { */ private String[] tokens; - private List names; + private List names; public DefaultFieldSet(String[] tokens) { this.tokens = tokens == null ? null : (String[]) tokens.clone(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java index a374c04d4..43b586115 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java @@ -134,7 +134,7 @@ final class PropertyMatches { * @param maxDistance the maximum distance to accept */ private String[] calculateMatches(PropertyDescriptor[] propertyDescriptors, int maxDistance) { - List candidates = new ArrayList(); + List candidates = new ArrayList(); for (int i = 0; i < propertyDescriptors.length; i++) { if (propertyDescriptors[i].getWriteMethod() != null) { String possibleAlternative = propertyDescriptors[i].getName(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/ResourceLineReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/ResourceLineReader.java index 79f43d299..7e6d24097 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/ResourceLineReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/separator/ResourceLineReader.java @@ -23,7 +23,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; @@ -54,7 +53,7 @@ import org.springframework.util.Assert; */ public class ResourceLineReader implements LineReader, ItemReader { - private static final Collection DEFAULT_COMMENTS = Collections.singleton("#"); + private static final Collection DEFAULT_COMMENTS = Collections.singleton("#"); private static final String DEFAULT_ENCODING = "ISO-8859-1"; @@ -64,7 +63,7 @@ public class ResourceLineReader implements LineReader, ItemReader { private final String encoding; - private Collection comments = DEFAULT_COMMENTS; + private Collection comments = DEFAULT_COMMENTS; // Encapsulates the state of the reader. private State state = null; @@ -103,7 +102,7 @@ public class ResourceLineReader implements LineReader, ItemReader { * @param comments an array of comment line prefixes. */ public void setComments(String[] comments) { - this.comments = new HashSet(Arrays.asList(comments)); + this.comments = new HashSet(Arrays.asList(comments)); } /** @@ -202,8 +201,7 @@ public class ResourceLineReader implements LineReader, ItemReader { } private boolean isComment(String line) { - for (Iterator iter = comments.iterator(); iter.hasNext();) { - String prefix = (String) iter.next(); + for (String prefix : comments) { if (line.startsWith(prefix)) { return true; }