Skip to content

Commit

Permalink
Merge pull request #9 from lvxnull2/utf8
Browse files Browse the repository at this point in the history
Always save config in utf-8 (lvxnull2)
  • Loading branch information
NotRyken authored Oct 26, 2024
2 parents 666f22d + 608fe65 commit f6ca545
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -210,7 +209,7 @@ public static Config resetAndSave() {
}

private static @Nullable Config load(Path file, Gson gson) {
try (FileReader reader = new FileReader(file.toFile())) {
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file.toFile()), StandardCharsets.UTF_8)) {
return gson.fromJson(reader, Config.class);
} catch (Exception e) {
// Catch Exception as errors in deserialization may not fall under
Expand All @@ -227,7 +226,7 @@ public static void save() {
Path file = DIR_PATH.resolve(FILE_NAME);
Path tempFile = file.resolveSibling(file.getFileName() + ".tmp");

try (FileWriter writer = new FileWriter(tempFile.toFile())) {
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile.toFile()), StandardCharsets.UTF_8)) {
writer.write(GSON.toJson(instance));
} catch (IOException e) {
throw new IOException(e);
Expand Down

0 comments on commit f6ca545

Please sign in to comment.