Java Code Examples for org.springframework.batch.item.file.LineMapper

The following examples show how to use org.springframework.batch.item.file.LineMapper. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Bean
public LineMapper<Voltage> lineMapper() {

    final DefaultLineMapper<Voltage> defaultLineMapper = new DefaultLineMapper<>();
    final DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
    lineTokenizer.setDelimiter(";");
    lineTokenizer.setStrict(false);
    lineTokenizer.setNames(new String[] {"volt","time"});

    final VoltageFieldSetMapper fieldSetMapper = new VoltageFieldSetMapper();
    defaultLineMapper.setLineTokenizer(lineTokenizer);
    defaultLineMapper.setFieldSetMapper(fieldSetMapper);

    return defaultLineMapper;
}
 
Example 2
@Bean
public LineMapper<PatientRecord> lineMapper() {
    DefaultLineMapper<PatientRecord> mapper = new DefaultLineMapper<>();
    mapper.setFieldSetMapper((fieldSet) -> new PatientRecord(
        fieldSet.readString(0), fieldSet.readString(1),
        fieldSet.readString(2), fieldSet.readString(3),
        fieldSet.readString(4), fieldSet.readString(5),
        fieldSet.readString(6), fieldSet.readString(7),
        fieldSet.readString(8), fieldSet.readString(9),
        fieldSet.readString(10), fieldSet.readString(11),
        fieldSet.readString(12)));
    mapper.setLineTokenizer(new DelimitedLineTokenizer());
    return mapper;
}
 
Example 3
@Bean
@JobScope
public FlatFileItemReader<BatchTaskAddress> fileItemReader(@Value("#{jobParameters['fileSource']}") final String pathToFile,
                                                           final LineMapper<BatchTaskAddress> lineMapper) throws
        Exception {
    final FlatFileItemReader<BatchTaskAddress> reader = new FlatFileItemReader<>();
    reader.setEncoding("utf-8");
    reader.setLineMapper(lineMapper);
    reader.setLinesToSkip(1);
    reader.setResource(new FileSystemResource(pathToFile));
    reader.afterPropertiesSet();
    return reader;
}
 
Example 4
@Bean
public LineMapper<Map<Object, Object>> lineMapper() {
	return (line, lineNumber) -> {
		Map<Object, Object> item = new HashMap<>(1);

		item.put("line", line);
		item.put("lineNumber", lineNumber);

		return item;
	};
}