import eu.svjatoslav.commons.string.tokenizer.Tokenizer;
import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch;
-import java.io.*;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import static eu.svjatoslav.commons.file.IOHelper.getFileContentsAsString;
import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.DROP;
import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.PRESERVE;
public static final String UTF_8 = "UTF-8";
public final List<Clazz> classes = new ArrayList<>();
- final StringBuffer contents = new StringBuffer();
+ String contents;
private final List<Import> imports = new ArrayList<>();
private final File file;
private String packageName;
public void parse() throws IOException, InvalidSyntaxException {
System.out.println("java file: " + file);
- readFile();
+ contents = getFileContentsAsString(file);
- final Tokenizer tokenizer = new Tokenizer(contents.toString());
+ final Tokenizer tokenizer = new Tokenizer(contents);
// empty space
tokenizer.addTerminator(" ", DROP);
tokenizer.expectAndConsumeNextToken(";");
}
- private void readFile() throws IOException {
- InputStreamReader inputStream = new InputStreamReader(new FileInputStream(file), UTF_8);
-
- final BufferedReader bufferedReader = new BufferedReader(inputStream);
-
- while (true) {
- final String line = bufferedReader.readLine();
-
- if (line == null)
- break;
-
- contents.append(line);
- contents.append("\n");
- }
-
- bufferedReader.close();
- inputStream.close();
- }
-
public void skipUntilSemicolon(final Tokenizer tokenizer) throws InvalidSyntaxException {
while (true) {
final TokenizerMatch token = tokenizer.getNextToken();