-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcmeReader.java
More file actions
40 lines (35 loc) · 1.06 KB
/
AcmeReader.java
File metadata and controls
40 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.javaee7.chapter11;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import javax.batch.api.chunk.AbstractItemReader;
/**
* Example of a file reading task
*
* @author Juneau
*/
public class AcmeReader extends AbstractItemReader {
public AcmeReader() {
}
/**
* Read lines of report and store each into a WidgetReportItem object. Once
* all lines have been read then return null to trigger the end of file.
* @return
* @throws Exception
*/
@Override
public List<WidgetReportItem> readItem() throws Exception {
Path file = Paths.get("widgetFile.txt");
List<String> fileLines;
List<WidgetReportItem> reportList = new ArrayList();
Charset charset = Charset.forName("US-ASCII");
fileLines = Files.readAllLines(file, charset);
for(String line:fileLines){
reportList.add(new WidgetReportItem(line));
}
return reportList;
}
}