1
0
mirror of https://e.coding.net/circlecloud/RealBackpacks.git synced 2024-12-04 03:49:07 +00:00

fix 1.7.2 lose Reader and update to 0.1.4...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-05-30 17:26:58 +08:00
parent 2889b376c5
commit e3f38801ac
3 changed files with 74 additions and 58 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.CityCraft</groupId>
<artifactId>RealBackpacks</artifactId>
<version>0.1.3-SNAPSHOT</version>
<version>0.1.4-SNAPSHOT</version>
<name>RealBackpacks</name>
<build>
<finalName>${project.name}</finalName>

View File

@ -1,5 +1,6 @@
package cn.citycraft.RealBackpacks.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;
@ -25,8 +27,8 @@ import com.google.common.base.Charsets;
import com.google.common.io.Files;
/**
* An implementation of {@link Configuration} which saves all files in Yaml.
* Note that this implementation is not synchronized.
* An implementation of {@link Configuration} which saves all files in Yaml. Note that this
* implementation is not synchronized.
*/
public class FileConfig extends YamlConfiguration {
@ -52,24 +54,38 @@ public class FileConfig extends YamlConfiguration {
protected final Representer yamlRepresenter = new YamlRepresenter();
protected final Yaml yaml = new Yaml(new YamlConstructor(),
yamlRepresenter, yamlOptions);
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");
Files.createParentDirs(file);
String data = saveToString();
Writer writer = new OutputStreamWriter(new FileOutputStream(file),
Charsets.UTF_8);
Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
try {
writer.write(data);
} finally {

View File

@ -1,6 +1,6 @@
name: RealBackpacks
main: cn.citycraft.RealBackpacks.RealBackpacks
version: 0.1.3
version: 0.1.4
author: Slayr288,喵♂呜
softdepend: [Vault]
commands: