1package com.runehive.util.parser;
3import com.google.common.base.Preconditions;
4import com.google.gson.Gson;
5import com.google.gson.GsonBuilder;
6import com.google.gson.JsonArray;
7import com.google.gson.JsonObject;
9import java.io.FileWriter;
38 private final Gson
serializer =
new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
43 private final JsonArray
array =
new JsonArray();
91 try (FileWriter fw =
new FileWriter(path)) {
93 }
catch (
final Exception e) {
117 Preconditions.checkState(!
singletonTable,
"JsonSaver instance is a singleton table!");
void split()
Adds the data within currentWriter to the internal JsonArray then instantiates a new writer,...
JsonObject currentWriter
A writer that acts as a sub-table, instantiated after each split().
void publish(String path)
Publishes the contents of this JsonSaver to the file at path.
String toString()
Invocation of this function is expensive and should be cached or avoided whenever possible.
JsonSaver(boolean singletonTable)
Creates a new JsonSaver.
final Gson serializer
A gson builder, allows us to turn Objects into JSON format and vice-versa.
final boolean singletonTable
The flag that determines if only one table can exist.
final JsonArray array
An array that will hold all of our sub-tables.
Gson serializer()
Gets the internal gson that allows for serialization.
JsonSaver()
Creates a new JsonSaver that can have an infinite amount of tables.