Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring for Parser.java #431

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* This class is thread safe.
*/
public class Parser {
private File file;
public synchronized void setFile(File f) {
file = f;
private final File file;

public Parser(File file) {
this.file = file;
}
public synchronized File getFile() {

public File getFile() {
return file;
}
public String getContent() throws IOException {
Expand All @@ -20,6 +22,7 @@ public String getContent() throws IOException {
while ((data = i.read()) > 0) {
output += (char) data;
}
i.close();
return output;
}
public String getContentWithoutUnicode() throws IOException {
Expand All @@ -31,12 +34,14 @@ public String getContentWithoutUnicode() throws IOException {
output += (char) data;
}
}
i.close();
return output;
}
public void saveContent(String content) throws IOException {
public synchronized void saveContent(String content) throws IOException {
FileOutputStream o = new FileOutputStream(file);
for (int i = 0; i < content.length(); i += 1) {
o.write(content.charAt(i));
}
o.close();
}
}