Upgrade to Java NIO

This commit is contained in:
Đạt Nhân Trương
2022-07-30 16:10:46 +07:00
parent d42a57ef79
commit a44744c05b
35 changed files with 553 additions and 500 deletions

View File

@@ -4,6 +4,8 @@ import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -26,8 +28,8 @@ import java.sql.SQLException;
* remove the property 'MonsterBook.img' inside 'string.wz' and choose to import the xml generated with this software.
*/
public class MobBookUpdate {
private static final File INPUT_FILE = new File(WZFiles.STRING.getFile(), "MonsterBook.img.xml");
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml");
private static final Path INPUT_FILE = WZFiles.STRING.getFile().resolve("MonsterBook.img.xml");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static PrintWriter printWriter = null;
@@ -143,23 +145,17 @@ public class MobBookUpdate {
}
private static void updateFromDropData() {
// This will reference one line at a time
String line = null;
try {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
while ((line = bufferedReader.readLine()) != null) {
try(con;
PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));
BufferedReader br = Files.newBufferedReader(INPUT_FILE);) {
printWriter = pw;
bufferedReader = br;
String line = null;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
printWriter.close();
bufferedReader.close();
fileReader.close();
con.close();
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + INPUT_FILE + "'");
} catch (IOException ex) {
@@ -170,6 +166,7 @@ public class MobBookUpdate {
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {