-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This feature dumps the entire chunk system state to disk, useful for debugging the chunk system state without a debugger.
- Loading branch information
1 parent
4911c50
commit 044a23f
Showing
4 changed files
with
211 additions
and
4 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/ca/spottedleaf/moonrise/common/util/JsonUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ca.spottedleaf.moonrise.common.util; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.internal.Streams; | ||
import com.google.gson.stream.JsonWriter; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.io.StringWriter; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public final class JsonUtil { | ||
|
||
public static void writeJson(final JsonElement element, final File file) throws IOException { | ||
final StringWriter stringWriter = new StringWriter(); | ||
final JsonWriter jsonWriter = new JsonWriter(stringWriter); | ||
jsonWriter.setIndent(" "); | ||
jsonWriter.setLenient(false); | ||
Streams.write(element, jsonWriter); | ||
|
||
final String jsonString = stringWriter.toString(); | ||
|
||
final File parent = file.getParentFile(); | ||
if (parent != null) { | ||
parent.mkdirs(); | ||
} | ||
file.createNewFile(); | ||
try (final PrintStream out = new PrintStream(new FileOutputStream(file), false, StandardCharsets.UTF_8)) { | ||
out.print(jsonString); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters