Revision 104,
1.2 KB
checked in by wojtekp, 13 years ago
(diff) |
|
-
Property svn:mime-type set to
text/plain
|
Line | |
---|
1 | package simulator.workload.reader.xmlJob; |
---|
2 | |
---|
3 | import java.io.BufferedReader; |
---|
4 | import java.io.File; |
---|
5 | import java.io.FileReader; |
---|
6 | import java.io.FilenameFilter; |
---|
7 | import java.io.IOException; |
---|
8 | |
---|
9 | import simulator.workload.fileFilters.GrmsJobFileNameFilter; |
---|
10 | |
---|
11 | /** |
---|
12 | * |
---|
13 | * @author Marcin Krystek |
---|
14 | * |
---|
15 | */ |
---|
16 | public class DirReader implements WLFileAccess { |
---|
17 | |
---|
18 | protected File files[]; |
---|
19 | protected int currentPosition; |
---|
20 | |
---|
21 | public DirReader(File dir){ |
---|
22 | FilenameFilter fileNameFilter = new GrmsJobFileNameFilter(); |
---|
23 | this.files = dir.listFiles(fileNameFilter); |
---|
24 | |
---|
25 | this.currentPosition = -1; |
---|
26 | } |
---|
27 | |
---|
28 | public String getFileName() { |
---|
29 | if(currentPosition >= this.files.length || currentPosition < 0) |
---|
30 | return null; |
---|
31 | |
---|
32 | return this.files[currentPosition].getAbsolutePath(); |
---|
33 | } |
---|
34 | |
---|
35 | public String read() throws IOException { |
---|
36 | currentPosition++; |
---|
37 | |
---|
38 | if(currentPosition >= files.length) |
---|
39 | return null; |
---|
40 | |
---|
41 | BufferedReader reader = null; |
---|
42 | StringBuffer buffer = new StringBuffer(); |
---|
43 | |
---|
44 | try { |
---|
45 | reader = new BufferedReader(new FileReader(files[currentPosition])); |
---|
46 | String line = null; |
---|
47 | |
---|
48 | while((line = reader.readLine()) != null){ |
---|
49 | buffer.append(line); |
---|
50 | } |
---|
51 | |
---|
52 | } finally{ |
---|
53 | reader.close(); |
---|
54 | } |
---|
55 | |
---|
56 | return buffer.toString(); |
---|
57 | } |
---|
58 | |
---|
59 | public void close() { |
---|
60 | |
---|
61 | } |
---|
62 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.