org.springframework.batch.item.file.transform.LineAggregator Java Examples
The following examples show how to use
org.springframework.batch.item.file.transform.LineAggregator.
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: FileItemWriterDemo.java From SpringAll with MIT License | 7 votes |
private FlatFileItemWriter<TestData> fileItemWriter() throws Exception { FlatFileItemWriter<TestData> writer = new FlatFileItemWriter<>(); FileSystemResource file = new FileSystemResource("/Users/mrbird/Desktop/file"); Path path = Paths.get(file.getPath()); if (!Files.exists(path)) { Files.createFile(path); } writer.setResource(file); // 设置目标文件路径 // 把读到的每个TestData对象转换为JSON字符串 LineAggregator<TestData> aggregator = item -> { try { ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(item); } catch (JsonProcessingException e) { e.printStackTrace(); } return ""; }; writer.setLineAggregator(aggregator); writer.afterPropertiesSet(); return writer; }
Example #2
Source File: ItemWriterConfigure.java From SpringAll with MIT License | 5 votes |
@Bean public FlatFileItemWriter<TestData> fileItemWriter() throws Exception { FlatFileItemWriter<TestData> writer = new FlatFileItemWriter<>(); FileSystemResource file = new FileSystemResource("/Users/mrbird/Desktop/file"); Path path = Paths.get(file.getPath()); if (!Files.exists(path)) { Files.createFile(path); } writer.setResource(file); // 设置目标文件路径 // 把读到的每个TestData对象转换为字符串 LineAggregator<TestData> aggregator = item -> { try { ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(item); } catch (JsonProcessingException e) { e.printStackTrace(); } return ""; }; writer.setLineAggregator(aggregator); writer.afterPropertiesSet(); return writer; }
Example #3
Source File: FlatFileItemWriterAutoConfigurationTests.java From spring-cloud-task with Apache License 2.0 | 4 votes |
@Bean public LineAggregator<Map<Object, Object>> lineAggregator() { return new PassThroughLineAggregator<>(); }
Example #4
Source File: HdfsTextItemWriter.java From spring-cloud-task-app-starters with Apache License 2.0 | 2 votes |
/** * Public setter for the {@link LineAggregator}. This will be used to translate the item into a line for output. * * @param lineAggregator the {@link LineAggregator} to set */ public void setLineAggregator(LineAggregator<T> lineAggregator) { this.lineAggregator = lineAggregator; }