blob: 9ca0b5ea90bdfc8dbf8713c93f81876c586460a3 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package com.jantuomi.interpreter.main.core;
import org.kohsuke.args4j.Option;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
* Created by jan on 10.6.2016.
*/
public class CommandLineArgumentContainer {
private CommandLineArgumentContainer() {}
private static final CommandLineArgumentContainer instance = new CommandLineArgumentContainer();
private File srcFile;
@Option(name="-f", usage="Execute script in file FILE.")
public void setFile(File file) {
this.srcFile = file;
}
public static CommandLineArgumentContainer getInstance() {
return instance;
}
public String getSourceFileContents() {
if (srcFile == null) {
return null;
}
BufferedReader br;
String contents = null;
try {
br = new BufferedReader(new FileReader(srcFile));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
contents = sb.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
// Add a newline at the end for comment rows to terminate nicely
return contents + "\n";
}
}
}
|