OPEN - issue BATCH-371: FlatFileItemWriter no longer uses LineAggregator
http://jira.springframework.org/browse/BATCH-371 Changed the interface of LineAggregator for symmetry with LineTokenizer.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.batch.io.file.transform;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
|
||||
|
||||
/**
|
||||
* Class used to create string representing object. Values are separated by
|
||||
@@ -30,13 +32,13 @@ public class DelimitedLineAggregator implements LineAggregator {
|
||||
/**
|
||||
* Method used to create string representing object.
|
||||
*
|
||||
* @param args arrays of strings representing data to be stored
|
||||
* @param fieldSet arrays of strings representing data to be stored
|
||||
* @param lineDescriptor for this implementation this parameter is not
|
||||
* used
|
||||
*/
|
||||
public String aggregate(String[] args) {
|
||||
public String aggregate(FieldSet fieldSet) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
String[] args = fieldSet.getValues();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
buffer.append(args[i]);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.batch.io.file.transform;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -60,14 +61,16 @@ public class FixedLengthLineAggregator implements LineAggregator {
|
||||
* Aggregate provided strings into single line using specified column
|
||||
* ranges.
|
||||
*
|
||||
* @param args
|
||||
* @param fieldSet
|
||||
* arrays of strings representing data to be aggregated
|
||||
* @return aggregated strings
|
||||
*/
|
||||
public String aggregate(String[] args) {
|
||||
public String aggregate(FieldSet fieldSet) {
|
||||
|
||||
Assert.notNull(args);
|
||||
Assert.notNull(fieldSet);
|
||||
Assert.notNull(ranges);
|
||||
|
||||
String[] args = fieldSet.getValues();
|
||||
Assert.isTrue(args.length <= ranges.length,
|
||||
"Number of arguments must match number of fields in a record");
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.batch.io.file.transform;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
|
||||
|
||||
/**
|
||||
* Interface used to create string used to create string representing object.
|
||||
@@ -26,9 +28,8 @@ public interface LineAggregator {
|
||||
/**
|
||||
* Method used to create a string to be stored from the array of values.
|
||||
*
|
||||
* @param args values to be stored
|
||||
* @param lineDescriptor structure of final string
|
||||
* @param fieldSet values to be converted
|
||||
* @return
|
||||
*/
|
||||
public String aggregate(String[] args);
|
||||
public String aggregate(FieldSet fieldSet);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.batch.io.file.transform;
|
||||
|
||||
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
|
||||
/**
|
||||
@@ -43,6 +45,14 @@ public class LineAggregatorItemTransformer implements ItemTransformer {
|
||||
* @see org.springframework.batch.item.writer.ItemTransformer#transform(java.lang.Object)
|
||||
*/
|
||||
public Object transform(Object item) throws Exception {
|
||||
return aggregator.aggregate((String[]) item);
|
||||
return aggregator.aggregate(createFieldSet(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
protected FieldSet createFieldSet(Object item) {
|
||||
return new DefaultFieldSet((String[]) item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user