Skip to content

Commit

Permalink
0.36
Browse files Browse the repository at this point in the history
0.36
  • Loading branch information
XenoAmess committed Dec 19, 2018
1 parent 9f8c00e commit 9fbe9d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xenoamess</groupId>
<artifactId>x8l</artifactId>
<version>0.35</version>
<version>0.36</version>
</project>
29 changes: 21 additions & 8 deletions src/main/java/com/xenoamess/x8l/X8lTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,57 @@ public class X8lTree {
public ContentNode root = null;
public Reader reader;

public static X8lTree LoadFromFile(File file) {
public static X8lTree LoadFromFile(File file) throws IOException {
if (file == null || !file.exists() || !file.isFile()) {
throw new FileNotFoundException();
}
X8lTree res = null;
FileReader fileReader = null;
try {
fileReader = new FileReader(file);
res = new X8lTree(fileReader);
res.parse();
} catch (FileNotFoundException e) {
e.printStackTrace();
throw e;
} finally {
try {
if (fileReader != null) {
fileReader.close();
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
return res;
}

public static void SaveToFile(File file, X8lTree x8lTree) {
public static void SaveToFile(File file, X8lTree x8lTree) throws IOException {
if (file == null || !file.isFile()) {
throw new FileNotFoundException();
}
if (!file.exists()) {
file.getParentFile().mkdirs();
try {
file.createNewFile();
} catch (IOException e) {
throw e;
}
}

FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(file);
x8lTree.output(fileWriter);
fileWriter.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
throw e;
} finally {
try {
if (fileWriter != null) {
fileWriter.close();
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
}
Expand Down

0 comments on commit 9fbe9d3

Please sign in to comment.