Line | |
---|
1 | package com.framsticks.parsers; |
---|
2 | |
---|
3 | import com.framsticks.params.SourceInterface; |
---|
4 | |
---|
5 | import java.io.BufferedReader; |
---|
6 | import java.io.FileReader; |
---|
7 | import java.io.IOException; |
---|
8 | |
---|
9 | |
---|
10 | public class FileSource implements SourceInterface { |
---|
11 | |
---|
12 | private BufferedReader reader; |
---|
13 | private String filename; |
---|
14 | |
---|
15 | public FileSource(String filename) throws IOException |
---|
16 | { |
---|
17 | this.filename = filename; |
---|
18 | reader = new BufferedReader(new FileReader(filename)); |
---|
19 | } |
---|
20 | |
---|
21 | |
---|
22 | @Override |
---|
23 | public String readLine() |
---|
24 | { |
---|
25 | try |
---|
26 | { |
---|
27 | return reader.readLine(); |
---|
28 | } catch (IOException ignored) { |
---|
29 | |
---|
30 | } |
---|
31 | return null; |
---|
32 | } |
---|
33 | |
---|
34 | @Override |
---|
35 | public String getFilename() |
---|
36 | { |
---|
37 | return filename; |
---|
38 | } |
---|
39 | |
---|
40 | @Override |
---|
41 | public String demangleInclude(String include) |
---|
42 | { |
---|
43 | if (!include.contains(java.io.File.separator)) { |
---|
44 | String currentFilePath = (new java.io.File(filename)).getParent(); |
---|
45 | if (!String.valueOf( |
---|
46 | currentFilePath.charAt(currentFilePath.length() - 1)) |
---|
47 | .equals(java.io.File.separator)) { |
---|
48 | currentFilePath = currentFilePath + java.io.File.separator; |
---|
49 | } |
---|
50 | include = currentFilePath + include; |
---|
51 | } |
---|
52 | return include; |
---|
53 | } |
---|
54 | |
---|
55 | @Override |
---|
56 | public SourceInterface openInclude(String include) |
---|
57 | { |
---|
58 | try |
---|
59 | { |
---|
60 | return new FileSource(include); |
---|
61 | } |
---|
62 | catch(IOException e) |
---|
63 | { |
---|
64 | |
---|
65 | } |
---|
66 | return null; |
---|
67 | } |
---|
68 | |
---|
69 | @Override |
---|
70 | public void close() |
---|
71 | { |
---|
72 | try { |
---|
73 | reader.close(); |
---|
74 | } catch (IOException e) { |
---|
75 | |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.