1 package org.sentrysoftware.jawk.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.FileReader;
28 import java.io.InputStream;
29 import java.io.Reader;
30 import org.slf4j.Logger;
31
32
33
34
35
36
37 public class ScriptFileSource extends ScriptSource {
38
39 private static final Logger LOG = AwkLogger.getLogger(ScriptFileSource.class);
40
41 private String filePath;
42 private Reader fileReader;
43 private InputStream fileInputStream;
44
45
46
47
48
49
50 public ScriptFileSource(String filePath) {
51 super(filePath, null, filePath.endsWith(".ai"));
52
53 this.filePath = filePath;
54 this.fileReader = null;
55 this.fileInputStream = null;
56 }
57
58
59
60
61
62
63 public String getFilePath() {
64 return filePath;
65 }
66
67
68 @Override
69 public Reader getReader() {
70
71 if ((fileReader == null) && !isIntermediate()) {
72 try {
73 fileReader = new FileReader(filePath);
74 } catch (FileNotFoundException ex) {
75 LOG.error("Failed to open script source for reading: " + filePath, ex);
76 }
77 }
78
79 return fileReader;
80 }
81
82
83 @Override
84 public InputStream getInputStream() {
85
86 if ((fileInputStream == null) && isIntermediate()) {
87 try {
88 fileInputStream = new FileInputStream(filePath);
89 } catch (FileNotFoundException ex) {
90 LOG.error("Failed to open script source for reading: " + filePath, ex);
91 }
92 }
93
94 return fileInputStream;
95 }
96 }