Java Code Examples for org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder

The following examples show how to use org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder. 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 FlatFileItemReader<Voltage> reader() {
    return new FlatFileItemReaderBuilder<Voltage>()
            .name("voltItemReader")
            .resource(new ClassPathResource("Volts.csv"))
            .delimited()
            .names(new String[]{"volt", "time"})
            .lineMapper(lineMapper())
            .fieldSetMapper(new BeanWrapperFieldSetMapper<Voltage>() {{
                setTargetType(Voltage.class);
            }})
            .build();
}
 
Example 2
Source Project: spring-graalvm-native   Source File: BatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@StepScope
public ItemStreamReader<CustomerCredit> itemReader() {
	return new FlatFileItemReaderBuilder<CustomerCredit>()
			.name("itemReader")
			.resource(new ClassPathResource("/customer.csv"))
			.delimited()
			.names("name", "credit")
			.targetType(CustomerCredit.class)
			.build();
}
 
Example 3
@Bean
public FlatFileItemReader<PayrollTo> reader() {
    return new FlatFileItemReaderBuilder<PayrollTo>()
            .name("payrollItemReader")
            .resource(new ClassPathResource("payroll-data.csv"))
            .delimited()
            .names(new String[]{"identification","currency","ammount","accountType", "accountNumber", "description", "firstLastName"})
            .fieldSetMapper(new BeanWrapperFieldSetMapper<PayrollTo>() {{
                setTargetType(PayrollTo.class);
            }})
            .build();
}
 
Example 4
Source Project: spring-batch-rest   Source File: PersonJobConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
FlatFileItemReader<Person> personReader() {
    return new FlatFileItemReaderBuilder<Person>()
            .name("personItemReader")
            .resource(new ClassPathResource("person.csv"))
            .delimited()
            .names("firstName", "lastName")
            .fieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {{
                setTargetType(Person.class);
            }})
            .build();
}
 
Example 5
Source Project: spring-batch-rest   Source File: PersonJobConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
FlatFileItemReader<Person> personReader() {
    return new FlatFileItemReaderBuilder<Person>()
            .name("personItemReader")
            .resource(new ClassPathResource("person.csv"))
            .delimited()
            .names(new String[]{"firstName", "lastName"})
            .fieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {{
                setTargetType(Person.class);
            }})
            .build();
}
 
Example 6
Source Project: spring-batch   Source File: CapitalizeNamesJobConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FlatFileItemReader<Person> itemReader() {
  return new FlatFileItemReaderBuilder<Person>()
      .name("personItemReader").delimited()
      .names(new String[] {"firstName", "lastName"})
      .targetType(Person.class).build();
}
 
Example 7
Source Project: spring-batch   Source File: CapitalizeNamesJobConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FlatFileItemReader<Person> itemReader() {
  return new FlatFileItemReaderBuilder<Person>()
      .name("personItemReader")
      .resource(new ClassPathResource("csv/persons.csv"))
      .delimited().names(new String[] {"firstName", "lastName"})
      .targetType(Person.class).build();
}
 
Example 8
Source Project: spring-batch   Source File: CapitalizeNamesJobConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FlatFileItemReader<Person> itemReader() {
  return new FlatFileItemReaderBuilder<Person>()
      .name("personItemReader")
      .resource(new ClassPathResource("csv/persons.csv"))
      .delimited().names(new String[] {"firstName", "lastName"})
      .targetType(Person.class).build();
}
 
Example 9
Source Project: spring-batch   Source File: CapitalizeNamesJobConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FlatFileItemReader<Person> itemReader() {
  return new FlatFileItemReaderBuilder<Person>()
      .name("personItemReader")
      .resource(new ClassPathResource("csv/persons.csv"))
      .delimited().names(new String[] {"firstName", "lastName"})
      .targetType(Person.class).build();
}
 
Example 10
Source Project: spring-batch   Source File: HelloWorldJobConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FlatFileItemReader<Person> reader() {
  return new FlatFileItemReaderBuilder<Person>()
      .name("personItemReader")
      .resource(new ClassPathResource("csv/persons.csv"))
      .delimited().names(new String[] {"firstName", "lastName"})
      .targetType(Person.class).build();
}
 
Example 11
Source Project: seed   Source File: StepService0006.java    License: Apache License 2.0 5 votes vote down vote up
private FlatFileItemReader<Person> reader(){
    return new FlatFileItemReaderBuilder<Person>()
            .name("step0001Reader")
            .resource(new FileSystemResource("/data/seedboot-batch.txt"))
            .strict(true)
            .encoding(SeedConstants.DEFAULT_CHARSET)
            .linesToSkip(1)
            .delimited().delimiter("|")
            .names(new String[]{"realName", "age", "birthDay"})
            .targetType(Person.class).customEditors(SettleJobConfiguration.customEditors)
            .build();
}
 
Example 12
Source Project: seed   Source File: StepService0004.java    License: Apache License 2.0 5 votes vote down vote up
private FlatFileItemReader<Person> reader(){
    return new FlatFileItemReaderBuilder<Person>()
            .name("step0001Reader")
            .resource(new FileSystemResource("/data/seedboot-batch.txt"))
            .strict(true)
            .encoding(SeedConstants.DEFAULT_CHARSET)
            .linesToSkip(1)
            .delimited().delimiter("|")
            .names(new String[]{"realName", "age", "birthDay"})
            .targetType(Person.class).customEditors(SettleJobConfiguration.customEditors)
            .build();
}
 
Example 13
@Bean
@StepScope
public FlatFileItemReader<PatientRecord> reader(
    @Value("#{jobParameters['" + Constants.JOB_PARAM_FILE_NAME + "']}")String fileName) {
    return new FlatFileItemReaderBuilder<PatientRecord>()
        .name(Constants.ITEM_READER_NAME)
        .resource(
            new PathResource(
                Paths.get(applicationProperties.getBatch().getInputPath() +
                    File.separator + fileName)))
        .linesToSkip(1)
        .lineMapper(lineMapper())
        .build();
}
 
Example 14
Source Project: messaging   Source File: BatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@StepScope
FlatFileItemReader<Contact> fileReader(
 @Value("file://#{jobParameters['file']}") Resource pathToFile)
 throws Exception {
 return new FlatFileItemReaderBuilder<Contact>().name("file-reader")
  .resource(pathToFile).targetType(Contact.class).delimited()
  .names("fullName,email".split(",")).build();
}
 
Example 15
Source Project: tutorials   Source File: SpringBatchScheduler.java    License: MIT License 5 votes vote down vote up
@Bean
public FlatFileItemReader<Book> reader() {
    return new FlatFileItemReaderBuilder<Book>().name("bookItemReader")
        .resource(new ClassPathResource("books.csv"))
        .delimited()
        .names(new String[] { "id", "name" })
        .fieldSetMapper(new BeanWrapperFieldSetMapper<Book>() {
            {
                setTargetType(Book.class);
            }
        })
        .build();
}
 
Example 16
Source Project: tutorials   Source File: SpringBatchConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
@StepScope
public FlatFileItemReader<BookRecord> csvItemReader(@Value("#{jobParameters['file.input']}") String input) {
    FlatFileItemReaderBuilder<BookRecord> builder = new FlatFileItemReaderBuilder<>();
    FieldSetMapper<BookRecord> bookRecordFieldSetMapper = new BookRecordFieldSetMapper();
    LOGGER.info("Configuring reader to input {}", input);
    // @formatter:off
    return builder
      .name("bookRecordItemReader")
      .resource(new FileSystemResource(input))
      .delimited()
      .names(TOKENS)
      .fieldSetMapper(bookRecordFieldSetMapper)
      .build();
    // @formatter:on
}
 
Example 17
Source Project: spring-batch   Source File: ConvertNamesJobConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public FlatFileItemReader<Person> itemReader() {
  return new FlatFileItemReaderBuilder<Person>().name("personItemReader")
      .resource(new ClassPathResource("csv/persons.csv")).delimited()
      .names(new String[] {"firstName", "lastName"}).targetType(Person.class).build();
}
 
Example 18
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.batch.job.flatfilereader", name = "name")
public FlatFileItemReader<Map<Object, Object>> itemReader() {
	FlatFileItemReaderBuilder<Map<Object, Object>> mapFlatFileItemReaderBuilder = new FlatFileItemReaderBuilder<Map<Object, Object>>()
			.name(this.properties.getName()).resource(this.properties.getResource())
			.saveState(this.properties.isSaveState())
			.maxItemCount(this.properties.getMaxItemCount())
			.currentItemCount(this.properties.getCurrentItemCount())
			.strict(this.properties.isStrict())
			.encoding(this.properties.getEncoding())
			.linesToSkip(this.properties.getLinesToSkip())
			.comments(this.properties.getComments()
					.toArray(new String[this.properties.getComments().size()]));

	if (this.lineTokenizer != null) {
		mapFlatFileItemReaderBuilder.lineTokenizer(this.lineTokenizer);
	}

	if (this.recordSeparatorPolicy != null) {
		mapFlatFileItemReaderBuilder
				.recordSeparatorPolicy(this.recordSeparatorPolicy);
	}

	if (this.fieldSetMapper != null) {
		mapFlatFileItemReaderBuilder.fieldSetMapper(this.fieldSetMapper);
	}

	if (this.lineMapper != null) {
		mapFlatFileItemReaderBuilder.lineMapper(this.lineMapper);
	}

	if (this.skippedLinesCallback != null) {
		mapFlatFileItemReaderBuilder.skippedLinesCallback(skippedLinesCallback);
	}

	if (this.properties.isDelimited()) {
		mapFlatFileItemReaderBuilder.delimited()
				.quoteCharacter(this.properties.getQuoteCharacter())
				.delimiter(this.properties.getDelimiter())
				.includedFields(
						this.properties.getIncludedFields().toArray(new Integer[0]))
				.names(this.properties.getNames())
				.beanMapperStrict(this.properties.isParsingStrict())
				.fieldSetMapper(new MapFieldSetMapper());
	}
	else if (this.properties.isFixedLength()) {
		mapFlatFileItemReaderBuilder.fixedLength()
				.columns(this.properties.getRanges().toArray(new Range[0]))
				.names(this.properties.getNames())
				.fieldSetMapper(new MapFieldSetMapper())
				.beanMapperStrict(this.properties.isParsingStrict());
	}

	return mapFlatFileItemReaderBuilder.build();
}