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

The following examples show how to use org.springframework.batch.item.file.LineMapper. 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
Source File: BatchJobConfiguration.java    From patient-batch-loader with GNU General Public License v3.0 7 votes vote down vote up
@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 #2
Source File: BatchConfiguration.java    From batch-processing-large-datasets-spring with MIT License 6 votes vote down vote up
@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 #3
Source File: AddressImportJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@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
Source File: FlatFileItemReaderAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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;
	};
}