Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 02:50:06 +01:00
Allow using custom input and output streams in subclasses of YAMLProcessor.
Dieser Commit ist enthalten in:
Ursprung
70205bfd11
Commit
2d8a4a9f8a
@ -25,11 +25,7 @@ import org.yaml.snakeyaml.constructor.SafeConstructor;
|
|||||||
import org.yaml.snakeyaml.reader.UnicodeReader;
|
import org.yaml.snakeyaml.reader.UnicodeReader;
|
||||||
import org.yaml.snakeyaml.representer.Representer;
|
import org.yaml.snakeyaml.representer.Representer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -95,10 +91,11 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
public void load() throws IOException {
|
public void load() throws IOException {
|
||||||
FileInputStream stream = null;
|
InputStream stream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stream = new FileInputStream(file);
|
stream = getInputStream();
|
||||||
|
if (stream == null) throw new IOException("Stream is null!");
|
||||||
read(yaml.load(new UnicodeReader(stream)));
|
read(yaml.load(new UnicodeReader(stream)));
|
||||||
} catch (YAMLProcessorException e) {
|
} catch (YAMLProcessorException e) {
|
||||||
root = new HashMap<String, Object>();
|
root = new HashMap<String, Object>();
|
||||||
@ -158,7 +155,7 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
* @return true if it was successful
|
* @return true if it was successful
|
||||||
*/
|
*/
|
||||||
public boolean save() {
|
public boolean save() {
|
||||||
FileOutputStream stream = null;
|
OutputStream stream = null;
|
||||||
|
|
||||||
File parent = file.getParentFile();
|
File parent = file.getParentFile();
|
||||||
|
|
||||||
@ -167,7 +164,8 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stream = new FileOutputStream(file);
|
stream = getOutputStream();
|
||||||
|
if (stream == null) return false;
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
|
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
|
||||||
if (header != null) {
|
if (header != null) {
|
||||||
writer.append(header);
|
writer.append(header);
|
||||||
@ -200,6 +198,14 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
return new FileInputStream(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutputStream getOutputStream() throws IOException {
|
||||||
|
return new FileOutputStream(file);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns an empty ConfigurationNode for using as a
|
* This method returns an empty ConfigurationNode for using as a
|
||||||
* default in methods that select a node from a node list.
|
* default in methods that select a node from a node list.
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren