Skip to content

Commit

Permalink
Add EnvJson#parse(InputStream)
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Dec 23, 2023
1 parent 3bc73fa commit 2b20931
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/fr/firstmegagame4/env/json/api/EnvJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.firstmegagame4.env.json.impl.EnvJsonParser;
import net.minecraft.util.Identifier;

import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;

Expand All @@ -12,6 +13,10 @@ static EnvJson parse(Path path) {
return new EnvJsonParser(path).toEnvJson();
}

static EnvJson parse(InputStream stream) {
return new EnvJsonParser(stream).toEnvJson();
}

List<EnvJsonMember> members();

Identifier apply(EnvJsonVisitor visitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.crash.CrashReport;
import org.jetbrains.annotations.ApiStatus;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,6 +39,10 @@ public EnvJsonParser(Path path) {
this.content = JsonParser.parseReader(reader).getAsJsonArray();
}

public EnvJsonParser(InputStream stream) {
this.content = JsonHelper.deserializeArray(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)));
}

private static SequenceEnvJsonRule parseSequenceRule(JsonObject json) {
return new SequenceEnvJsonRuleImpl(EnvJsonParser.parseRules(json.getAsJsonObject()));
}
Expand Down

0 comments on commit 2b20931

Please sign in to comment.