From c26705e6b13a011aa28bd6946740b09f7da9057b Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 7 Nov 2018 19:41:50 +1100 Subject: [PATCH] Improve YamlConfiguration encoding defaults Before: Load / Save using platform default (UTF-8 on most except Windows) After: Load using detected encoding with fallback to UTF-8 Save using UTF-8 --- .../net/md_5/bungee/config/YamlConfiguration.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/config/src/main/java/net/md_5/bungee/config/YamlConfiguration.java b/config/src/main/java/net/md_5/bungee/config/YamlConfiguration.java index db8aa4be..bb974a4a 100644 --- a/config/src/main/java/net/md_5/bungee/config/YamlConfiguration.java +++ b/config/src/main/java/net/md_5/bungee/config/YamlConfiguration.java @@ -1,10 +1,12 @@ package net.md_5.bungee.config; +import com.google.common.base.Charsets; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.util.LinkedHashMap; @@ -51,7 +53,7 @@ public class YamlConfiguration extends ConfigurationProvider @Override public void save(Configuration config, File file) throws IOException { - try ( FileWriter writer = new FileWriter( file ) ) + try ( Writer writer = new OutputStreamWriter( new FileOutputStream( file ), Charsets.UTF_8 ) ) { save( config, writer ); } @@ -72,9 +74,9 @@ public class YamlConfiguration extends ConfigurationProvider @Override public Configuration load(File file, Configuration defaults) throws IOException { - try ( FileReader reader = new FileReader( file ) ) + try ( FileInputStream is = new FileInputStream( file ) ) { - return load( reader, defaults ); + return load( is, defaults ); } }