org.springframework.batch.item.file.builder.FlatFileItemWriterBuilder Java Examples
The following examples show how to use
org.springframework.batch.item.file.builder.FlatFileItemWriterBuilder.
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: BatchConfiguration.java From spring-graalvm-native with Apache License 2.0 | 5 votes |
@Bean @StepScope public ResourceAwareItemWriterItemStream<CustomerCredit> itemWriter(@Value("#{jobParameters[outputFile]}") Resource resource) { return new FlatFileItemWriterBuilder<CustomerCredit>() .name("itemWriter") .resource(resource) .delimited() .names("credit", "name") .build(); }
Example #2
Source File: CapitalizeNamesJobConfig.java From spring-batch with MIT License | 5 votes |
@Bean public FlatFileItemWriter<Person> itemWriter() { return new FlatFileItemWriterBuilder<Person>() .name("personItemWriter") .resource(new FileSystemResource( "target/test-outputs/persons.txt")) .delimited().delimiter(", ") .names(new String[] {"firstName", "lastName"}).build(); }
Example #3
Source File: CapitalizeNamesJobConfig.java From spring-batch with MIT License | 5 votes |
@Bean public FlatFileItemWriter<Person> itemWriter() { return new FlatFileItemWriterBuilder<Person>() .name("personItemWriter") .resource(new FileSystemResource( "target/test-outputs/persons.txt")) .delimited().delimiter(", ") .names(new String[] {"firstName", "lastName"}).build(); }
Example #4
Source File: CapitalizeNamesJobConfig.java From spring-batch with MIT License | 5 votes |
@Bean public FlatFileItemWriter<Person> itemWriter() { return new FlatFileItemWriterBuilder<Person>() .name("personItemWriter") .resource(new FileSystemResource( "target/test-outputs/persons.txt")) .delimited().delimiter(", ") .names(new String[] {"firstName", "lastName"}).build(); }
Example #5
Source File: HelloWorldJobConfig.java From spring-batch with MIT License | 5 votes |
@Bean public FlatFileItemWriter<String> writer() { return new FlatFileItemWriterBuilder<String>() .name("greetingItemWriter") .resource(new FileSystemResource( "target/test-outputs/greetings.txt")) .lineAggregator(new PassThroughLineAggregator<>()).build(); }
Example #6
Source File: ConvertNamesJobConfig.java From spring-batch with MIT License | 4 votes |
@Bean public FlatFileItemWriter<Person> itemWriter() { return new FlatFileItemWriterBuilder<Person>().name("personItemWriter") .resource(new FileSystemResource("target/test-outputs/persons.txt")) .lineAggregator(new PassThroughLineAggregator<>()).build(); }
Example #7
Source File: CapitalizeNamesJobConfig.java From spring-batch with MIT License | 4 votes |
@Bean public FlatFileItemWriter<Person> itemWriter() { return new FlatFileItemWriterBuilder<Person>() .name("personItemWriter") .resource(new FileSystemResource( "target/test-outputs/persons.txt")) .delimited().delimiter(", ") .names(new String[] {"firstName", "lastName"}).build(); }
Example #8
Source File: FlatFileItemWriterAutoConfiguration.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = "spring.batch.job.flatfilewriter", name = "name") public FlatFileItemWriter<Map<Object, Object>> itemWriter() { if (this.properties.isDelimited() && this.properties.isFormatted()) { throw new IllegalStateException( "An output file must be either delimited or formatted or a custom " + "LineAggregator must be provided. Your current configuration specifies both delimited and formatted"); } else if ((this.properties.isFormatted() || this.properties.isDelimited()) && this.lineAggregator != null) { throw new IllegalStateException("A LineAggregator must be configured if the " + "output is not formatted or delimited"); } FlatFileItemWriterBuilder<Map<Object, Object>> builder = new FlatFileItemWriterBuilder<Map<Object, Object>>() .name(this.properties.getName()).resource(this.properties.getResource()) .append(this.properties.isAppend()) .encoding(this.properties.getEncoding()) .forceSync(this.properties.isForceSync()) .lineSeparator(this.properties.getLineSeparator()) .saveState(this.properties.isSaveState()) .shouldDeleteIfEmpty(this.properties.isShouldDeleteIfEmpty()) .shouldDeleteIfExists(this.properties.isShouldDeleteIfExists()) .transactional(this.properties.isTransactional()) .headerCallback(this.headerCallback).footerCallback(this.footerCallback); if (this.properties.isDelimited()) { FlatFileItemWriterBuilder.DelimitedBuilder<Map<Object, Object>> delimitedBuilder = builder .delimited().delimiter(this.properties.getDelimiter()); if (this.fieldExtractor != null) { delimitedBuilder.fieldExtractor(this.fieldExtractor); } else { delimitedBuilder.fieldExtractor( new MapFieldExtractor(this.properties.getNames())); } } else if (this.properties.isFormatted()) { FlatFileItemWriterBuilder.FormattedBuilder<Map<Object, Object>> formattedBuilder = builder .formatted().format(this.properties.getFormat()) .locale(this.properties.getLocale()) .maximumLength(this.properties.getMaximumLength()) .minimumLength(this.properties.getMinimumLength()); if (this.fieldExtractor != null) { formattedBuilder.fieldExtractor(this.fieldExtractor); } else { formattedBuilder.fieldExtractor( new MapFieldExtractor(this.properties.getNames())); } } else if (this.lineAggregator != null) { builder.lineAggregator(this.lineAggregator); } return builder.build(); }