From dfd79af897d3dabdf0da6603e14fef37ae5dc9c1 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Sat, 30 May 2015 17:39:36 +0800 Subject: [PATCH] update FileConfig class... Signed-off-by: j502647092 --- .../bukkit/residence/config/FileConfig.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/com/bekvon/bukkit/residence/config/FileConfig.java b/src/com/bekvon/bukkit/residence/config/FileConfig.java index 2e72877..f097d25 100644 --- a/src/com/bekvon/bukkit/residence/config/FileConfig.java +++ b/src/com/bekvon/bukkit/residence/config/FileConfig.java @@ -1,5 +1,6 @@ package com.bekvon.bukkit.residence.config; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -7,6 +8,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.io.Reader; import java.io.Writer; import java.util.logging.Level; @@ -60,13 +62,29 @@ public class FileConfig extends YamlConfiguration { protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); @Override - public void load(File file) throws FileNotFoundException, IOException, - InvalidConfigurationException { + public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException { Validate.notNull(file, "File cannot be null"); final FileInputStream stream = new FileInputStream(file); load(new InputStreamReader(stream, Charsets.UTF_8)); } + @Override + public void load(Reader reader) throws IOException, InvalidConfigurationException { + BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader + : new BufferedReader(reader); + StringBuilder builder = new StringBuilder(); + try { + String line; + while ((line = input.readLine()) != null) { + builder.append(line); + builder.append('\n'); + } + } finally { + input.close(); + } + loadFromString(builder.toString()); + } + @Override public void save(File file) throws IOException { Validate.notNull(file, "File cannot be null");