use of org.springframework.batch.item.file.transform.DelimitedLineTokenizer in project microservices by pwillhan.
the class ContactBatchJobConfiguration method reader.
@Bean
public ItemReader<Contact> reader() {
FlatFileItemReader<Contact> reader = new FlatFileItemReader<>();
reader.setResource(new ClassPathResource("data.csv"));
reader.setLineMapper(new DefaultLineMapper<Contact>() {
{
setLineTokenizer(new DelimitedLineTokenizer() {
{
setNames(new String[] { "firstName", "lastName", "email" });
}
});
setFieldSetMapper(new BeanWrapperFieldSetMapper<Contact>() {
{
setTargetType(Contact.class);
}
});
}
});
return reader;
}
use of org.springframework.batch.item.file.transform.DelimitedLineTokenizer 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.transform.DelimitedLineTokenizer 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.transform.DelimitedLineTokenizer in project microservices by pwillhan.
the class BatchConfiguration method flatFileItemReader.
@Bean
@StepScope
FlatFileItemReader<Person> flatFileItemReader(@Value("#{jobParameters[file]}") File file) {
FlatFileItemReader<Person> r = new FlatFileItemReader<>();
r.setResource(new FileSystemResource(file));
r.setLineMapper(new DefaultLineMapper<Person>() {
{
this.setLineTokenizer(new DelimitedLineTokenizer(",") {
{
this.setNames(new String[] { "first", "last", "email" });
}
});
this.setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {
{
this.setTargetType(Person.class);
}
});
}
});
return r;
}
Aggregations