From b2f519fd934cd49afbb5cfc88b3d2be396af0afa Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 8 Jun 2020 21:05:18 +0300 Subject: [PATCH] Use common library to read file content. --- .../inspector/java/methods/JavaFile.java | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java b/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java index 09469f8..70d5dc2 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/JavaFile.java @@ -13,10 +13,12 @@ import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; 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; @@ -24,7 +26,7 @@ public class JavaFile { public static final String UTF_8 = "UTF-8"; public final List classes = new ArrayList<>(); - final StringBuffer contents = new StringBuffer(); + String contents; private final List imports = new ArrayList<>(); private final File file; private String packageName; @@ -37,9 +39,9 @@ public class JavaFile { 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); @@ -154,25 +156,6 @@ public class JavaFile { 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(); -- 2.20.1