java - Spring Batch - FlatFileItemWriter write to a file, close it, write to new file -
so have custom class extends flatfileitemwriter using write csv file. based on condition want finish first file , write new file. there way flatfileitemwriter?
here example of code:
@override public void write(list<? extends myobject> items) throws exception { executioncontext stepcontext = this.stepexecution.getexecutioncontext(); int currentfileincrememnt = (int) stepcontext.get("currentfileincrement"); if(currentfileincrement== fileincrement) { super.write(items); } else { super.close(); fileincrement = currentfileincrement; super.setheadercallback(determineheadercallback()); super.setresource(new filesystemresource("src/main/resources/" + fileincrement+ ".csv")); super.setshoulddeleteifexists(true); delimitedlineaggregator<myobject> dellineagg = new delimitedlineaggregator<>(); dellineagg.setdelimiter(","); beanwrapperfieldextractor<myobject> fieldextractor = new beanwrapperfieldextractor<>(); fieldextractor.setnames(new string[] {"id", "amount"}); dellineagg.setfieldextractor(fieldextractor); super.setlineaggregator(dellineagg); super.write(items); } }
i don t understand if using custom writer or spring one. if using custom (maybe extendig spring one) use whatever want passing parameters through processor, reader o mapper. if want use spring writer should make isolated steps. give more details.
Comments
Post a Comment