Java Reference
In-Depth Information
public WidgetReportItem readItem() throws Exception {
Path file = Paths.get("widgetFile.txt");
List<String> fileLines;
Charset charset = Charset.forName("US-ASCII");
fileLines = Files.readAllLines(file, charset);
for(String line:fileLines){
return new WidgetReportItem(line);
}
return null;
}
}
Next, let's take a look at the AcmeProcessor class. This class is responsible for processing each WidgetReportItem
accordingly. In this case, if the line of text that is contained in the object has the text “Two” in it, then it will be added
to a WidgetOutputItem object.
package org.javaee7.chapter11;
import javax.batch.api.ItemProcessor;
/**
*
* @author Juneau
*/
public class AcmeProcessor implements ItemProcessor<WidgetReportItem, WidgetOutputItem> {
public AcmeProcessor(){}
/**
* Write out all lines that contain the text "Two"
* @param item
* @return
* @throws Exception
*/
@Override
public WidgetOutputItem processItem(WidgetReportItem item) throws Exception {
if(item.getLineText().contains("Two")){
return new WidgetOutputItem(item.getLineText());
} else {
return null;
}
}
}
Lastly, let's see what the AcmeWriter class looks like. This class is responsible for writing the WidgetOutputItem
objects that have been processed by AcmeProcessor .
package org.javaee7.chapter11;
 
Search WWH ::




Custom Search