use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project tutorials by eugenp.
the class SpringBatchConfig method itemReader.
@Bean
public ItemReader<Transaction> itemReader() throws UnexpectedInputException, ParseException {
FlatFileItemReader<Transaction> reader = new FlatFileItemReader<Transaction>();
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
String[] tokens = { "username", "userid", "transactiondate", "amount" };
tokenizer.setNames(tokens);
reader.setResource(inputCsv);
DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<Transaction>();
lineMapper.setLineTokenizer(tokenizer);
lineMapper.setFieldSetMapper(new RecordFieldSetMapper());
reader.setLinesToSkip(1);
reader.setLineMapper(lineMapper);
return reader;
}
use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project tutorials by eugenp.
the class SpringbatchPartitionConfig method itemReader.
@Bean
@StepScope
public FlatFileItemReader<Transaction> itemReader(@Value("#{stepExecutionContext[fileName]}") String filename) throws UnexpectedInputException, ParseException {
FlatFileItemReader<Transaction> reader = new FlatFileItemReader<>();
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
String[] tokens = { "username", "userid", "transactiondate", "amount" };
tokenizer.setNames(tokens);
reader.setResource(new ClassPathResource("input/partitioner/" + filename));
DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<>();
lineMapper.setLineTokenizer(tokenizer);
lineMapper.setFieldSetMapper(new RecordFieldSetMapper());
reader.setLinesToSkip(1);
reader.setLineMapper(lineMapper);
return reader;
}
use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project pkslow-samples by LarryDpk.
the class JobConfig method reader.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public FlatFileItemReader<Employee> reader() {
// Create reader instance
FlatFileItemReader<Employee> reader = new FlatFileItemReader<Employee>();
// Set number of lines to skips. Use it if file has header rows.
reader.setLinesToSkip(1);
// Configure how each line will be parsed and mapped to different values
reader.setLineMapper(new DefaultLineMapper() {
{
// 3 columns in each row
setLineTokenizer(new DelimitedLineTokenizer() {
{
setNames(new String[] { "id", "firstName", "lastName" });
}
});
// Set values in Employee class
setFieldSetMapper(new BeanWrapperFieldSetMapper<Employee>() {
{
setTargetType(Employee.class);
}
});
}
});
return reader;
}
use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project invesdwin-nowicket by invesdwin.
the class CsvItemReaderBuilder method newDefaultLineMapper.
private DefaultLineMapper<T> newDefaultLineMapper() {
final DefaultLineMapper<T> lineMapper = new DefaultLineMapper<T>();
final DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
if (delimiter != null) {
tokenizer.setDelimiter(delimiter);
}
if (names != null) {
tokenizer.setNames(names);
}
if (strict != null) {
tokenizer.setStrict(strict);
}
if (fieldSetFactory != null) {
tokenizer.setFieldSetFactory(fieldSetFactory);
}
lineMapper.setLineTokenizer(tokenizer);
if (fieldSetMapper != null) {
lineMapper.setFieldSetMapper(fieldSetMapper);
}
lineMapper.afterPropertiesSet();
return lineMapper;
}
use of org.springframework.batch.item.file.mapping.DefaultLineMapper in project invesdwin-context by invesdwin.
the class CsvItemReaderBuilder method newDefaultLineMapper.
private DefaultLineMapper<T> newDefaultLineMapper() {
final DefaultLineMapper<T> lineMapper = new DefaultLineMapper<T>();
final DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
if (delimiter != null) {
tokenizer.setDelimiter(delimiter);
}
if (names != null) {
tokenizer.setNames(names);
}
if (strict != null) {
tokenizer.setStrict(strict);
}
if (fieldSetFactory != null) {
tokenizer.setFieldSetFactory(fieldSetFactory);
}
lineMapper.setLineTokenizer(tokenizer);
if (fieldSetMapper != null) {
lineMapper.setFieldSetMapper(fieldSetMapper);
}
lineMapper.afterPropertiesSet();
return lineMapper;
}
Aggregations