Java 类org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonWriter 实例源码

项目:PartyLobby    文件:FancyMessage.java   
/**
 * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
 * This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
 * @return The JSON string representing this object.
 */
public String toJSONString() {
    if (!dirty && jsonString != null) {
        return jsonString;
    }
    StringWriter string = new StringWriter();
    JsonWriter json = new JsonWriter(string);
    try {
        writeJson(json);
        json.close();
    } catch (Exception e) {
        throw new RuntimeException("invalid message");
    }
    jsonString = string.toString();
    dirty = false;
    return jsonString;
}
项目:AwesomeDeathMessages    文件:FancyMessage.java   
/**
 * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
 * This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
 * @return The JSON string representing this object.
 */
public String toJSONString() {
    if (!dirty && jsonString != null) {
        return jsonString;
    }
    StringWriter string = new StringWriter();
    JsonWriter json = new JsonWriter(string);
    try {
        writeJson(json);
        json.close();
    } catch (IOException e) {
        throw new RuntimeException("invalid message");
    }
    jsonString = string.toString();
    dirty = false;
    return jsonString;
}
项目:EndHQ-Libraries    文件:JSONMessage.java   
/**
 * Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
 * This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
 * @return The JSON string representing this object.
 */
public String toJSONString() {
    if (!dirty && jsonString != null) {
        return jsonString;
    }
    StringWriter string = new StringWriter();
    JsonWriter json = new JsonWriter(string);
    try {
        writeJson(json);
        json.close();
    } catch (IOException e) {
        throw new RuntimeException("invalid message");
    }
    jsonString = string.toString();
    dirty = false;
    return jsonString;
}
项目:SparkTrail    文件:FancyMessage.java   
public String toJSONString() {
    if (!dirty && jsonString != null) {
        return jsonString;
    }
    StringWriter string = new StringWriter();
    JsonWriter json = new JsonWriter(string);
    try {
        if (messageParts.size() == 1) {
            latest().writeJson(json);
        } else {
            json.beginObject().name("text").value("").name("extra").beginArray();
            for (final MessagePart part : messageParts) {
                part.writeJson(json);
            }
            json.endArray().endObject();
            json.close();
        }
    } catch (Exception e) {
        throw new RuntimeException("invalid message");
    }
    jsonString = string.toString();
    dirty = false;
    return jsonString;
}
项目:SparkTrail    文件:FancyMessage.java   
private String makeMultilineTooltip(final String[] lines) {
    StringWriter string = new StringWriter();
    JsonWriter json = new JsonWriter(string);
    try {
        json.beginObject().name("id").value(1);
        json.name("tag").beginObject().name("display").beginObject();
        json.name("Name").value("\\u00A7f" + lines[0].replace("\"", "\\\""));
        json.name("Lore").beginArray();
        for (int i = 1; i < lines.length; i++) {
            final String line = lines[i];
            json.value(line.isEmpty() ? " " : line.replace("\"", "\\\""));
        }
        json.endArray().endObject().endObject().endObject();
        json.close();
    } catch (Exception e) {
        throw new RuntimeException("invalid tooltip");
    }
    return string.toString();
}
项目:PartyLobby    文件:MessagePart.java   
public void writeJson(JsonWriter json) {
    try {
        json.beginObject();
        text.writeJson(json);
        json.name("color").value(color.name().toLowerCase());
        for (final ChatColor style : styles) {
            json.name(stylesToNames.get(style)).value(true);
        }
        if (clickActionName != null && clickActionData != null) {
            json.name("clickEvent")
            .beginObject()
            .name("action").value(clickActionName)
            .name("value").value(clickActionData)
            .endObject();
        }
        if (hoverActionName != null && hoverActionData != null) {
            json.name("hoverEvent")
            .beginObject()
            .name("action").value(hoverActionName)
            .name("value");
            hoverActionData.writeJson(json);
            json.endObject();
        }
        json.endObject();
    } catch(Exception e){
        e.printStackTrace();
    }
}
项目:PartyLobby    文件:FancyMessage.java   
public void writeJson(JsonWriter writer) throws IOException{
    if (messageParts.size() == 1) {
        latest().writeJson(writer);
    } else {
        writer.beginObject().name("text").value("").name("extra").beginArray();
        for (final MessagePart part : this) {
            part.writeJson(writer);
        }
        writer.endArray().endObject();
    }
}
项目:PartyLobby    文件:TextualComponent.java   
@Override
public void writeJson(JsonWriter writer) throws IOException {
    writer.name(getKey());
    writer.beginObject();
    for(Map.Entry<String, String> jsonPair : _value.entrySet()){
        writer.name(jsonPair.getKey()).value(jsonPair.getValue());
    }
    writer.endObject();
}
项目:AwesomeDeathMessages    文件:MessagePart.java   
public void writeJson(JsonWriter json) {
    try {
        json.beginObject();
        text.writeJson(json);
        json.name("color").value(color.name().toLowerCase());
        for (final ChatColor style : styles) {
            json.name(stylesToNames.get(style)).value(true);
        }
        if (clickActionName != null && clickActionData != null) {
            json.name("clickEvent")
            .beginObject()
            .name("action").value(clickActionName)
            .name("value").value(clickActionData)
            .endObject();
        }
        if (hoverActionName != null && hoverActionData != null) {
            json.name("hoverEvent")
            .beginObject()
            .name("action").value(hoverActionName)
            .name("value");
            hoverActionData.writeJson(json);
            json.endObject();
        }
        json.endObject();
    } catch(IOException e){
        Bukkit.getLogger().log(Level.WARNING, "A problem occured during writing of JSON string", e);
    }
}
项目:AwesomeDeathMessages    文件:FancyMessage.java   
public void writeJson(JsonWriter writer) throws IOException{
    if (messageParts.size() == 1) {
        latest().writeJson(writer);
    } else {
        writer.beginObject().name("text").value("").name("extra").beginArray();
        for (final MessagePart part : this) {
            part.writeJson(writer);
        }
        writer.endArray().endObject();
    }
}
项目:AwesomeDeathMessages    文件:TextualComponent.java   
@Override
public void writeJson(JsonWriter writer) throws IOException {
    writer.name(getKey());
    writer.beginObject();
    for(Map.Entry<String, String> jsonPair : _value.entrySet()){
        writer.name(jsonPair.getKey()).value(jsonPair.getValue());
    }
    writer.endObject();
}
项目:Ipsum    文件:JsonPlayer.java   
/**
 * Save to the {@link com.relicum.ipsum.Configuration.PersistentPlayer} object to disk in JSON format.
 *
 * @param persistentPlayer the {@link com.relicum.ipsum.Configuration.PersistentPlayer} that will be serialized to JSON and saved to disk
 */
public void saveToDisk(PersistentPlayer persistentPlayer) {

    try {
        JsonWriter jsonWriter = GsonIO.writer(Paths.get(stringPath, persistentPlayer.getUuid() + ".json"));
        jsonWriter.setIndent("    ");
        gson.toJson(persistentPlayer, type, jsonWriter);
        jsonWriter.flush();
        jsonWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:Ipsum    文件:GsonRaw.java   
public static void writeToFile(Path path, Object src, Type typeOfSrc) throws IOException {

        JsonWriter writer = writer(path);

        gson.toJson(src, typeOfSrc, writer);
        writer.flush();
        writer.close();
    }
项目:Ipsum    文件:GsonIO.java   
public static void writeToFile(Path path, Object src, Type typeOfSrc) throws IOException {

        JsonWriter writer = writer(path);
        writer.setIndent("    ");

        gson.toJson(src, typeOfSrc, writer);
        writer.flush();
        writer.close();
    }
项目:EndHQ-Libraries    文件:JSONMessage.java   
public void writeJson(JsonWriter writer) throws IOException{
    if (messageParts.size() == 1) {
        latest().writeJson(writer);
    } else {
        writer.beginObject().name("text").value("").name("extra").beginArray();
        for (final MessagePart part : this) {
            part.writeJson(writer);
        }
        writer.endArray().endObject();
    }
}
项目:EndHQ-Libraries    文件:MessagePart.java   
public void writeJson(JsonWriter json) {
    try {
        json.beginObject();
        text.writeJson(json);
        json.name("color").value(color.name().toLowerCase());
        for (final ChatColor style : styles) {
            json.name(stylesToNames.get(style)).value(true);
        }
        if (clickActionName != null && clickActionData != null) {
            json.name("clickEvent")
            .beginObject()
            .name("action").value(clickActionName)
            .name("value").value(clickActionData)
            .endObject();
        }
        if (hoverActionName != null && hoverActionData != null) {
            json.name("hoverEvent")
            .beginObject()
            .name("action").value(hoverActionName)
            .name("value");
            hoverActionData.writeJson(json);
            json.endObject();
        }
        json.endObject();
    } catch(IOException e){
        Bukkit.getLogger().log(Level.WARNING, "A problem occured during writing of JSON string", e);
    }
}
项目:EndHQ-Libraries    文件:TextualComponent.java   
@Override
public void writeJson(JsonWriter writer) throws IOException {
    writer.name(getKey());
    writer.beginObject();
    for(Map.Entry<String, String> jsonPair : _value.entrySet()){
        writer.name(jsonPair.getKey()).value(jsonPair.getValue());
    }
    writer.endObject();
}
项目:SparkTrail    文件:MessagePart.java   
JsonWriter writeJson(JsonWriter json) {
    try {
        json.beginObject().name("text").value(text);
        if (color != null) {
            json.name("color").value(color.name().toLowerCase());
        }
        if (styles != null) {
            for (final ChatColor style : styles) {
                json.name(style.name().toLowerCase()).value(true);
            }
        }
        if (clickActionName != null && clickActionData != null) {
            json.name("clickEvent")
                    .beginObject()
                    .name("action").value(clickActionName)
                    .name("value").value(clickActionData)
                    .endObject();
        }
        if (hoverActionName != null && hoverActionData != null) {
            json.name("hoverEvent")
                    .beginObject()
                    .name("action").value(hoverActionName)
                    .name("value").value(hoverActionData)
                    .endObject();
        }
        return json.endObject();
    } catch (Exception e) {
        e.printStackTrace();
        return json;
    }
}
项目:PartyLobby    文件:JsonString.java   
public void writeJson(JsonWriter writer) throws IOException {
    writer.value(getValue());
}
项目:PartyLobby    文件:TextualComponent.java   
@Override
public void writeJson(JsonWriter writer) throws IOException {
    writer.name(getKey()).value(getValue());
}
项目:AwesomeDeathMessages    文件:JsonString.java   
public void writeJson(JsonWriter writer) throws IOException {
    writer.value(getValue());
}
项目:AwesomeDeathMessages    文件:TextualComponent.java   
@Override
public void writeJson(JsonWriter writer) throws IOException {
    writer.name(getKey()).value(getValue());
}
项目:EndHQ-Libraries    文件:JsonString.java   
public void writeJson(JsonWriter writer) throws IOException {
    writer.value(getValue());
}
项目:EndHQ-Libraries    文件:TextualComponent.java   
@Override
public void writeJson(JsonWriter writer) throws IOException {
    writer.name(getKey()).value(getValue());
}
项目:PartyLobby    文件:JsonRepresentedObject.java   
/**
 * Writes the JSON representation of this object to the specified writer.
 * @param writer The JSON writer which will receive the object.
 * @throws IOException If an error occurs writing to the stream.
 */
public void writeJson(JsonWriter writer) throws IOException;
项目:PartyLobby    文件:TextualComponent.java   
/**
 * Writes the text data represented by this textual component to the specified JSON writer object.
 * A new object within the writer is not started.
 * @param writer The object to which to write the JSON data.
 * @throws IOException If an error occurs while writing to the stream.
 */
public abstract void writeJson(JsonWriter writer) throws IOException;
项目:AwesomeDeathMessages    文件:JsonRepresentedObject.java   
/**
 * Writes the JSON representation of this object to the specified writer.
 * @param writer The JSON writer which will receive the object.
 * @throws IOException If an error occurs writing to the stream.
 */
public void writeJson(JsonWriter writer) throws IOException;
项目:AwesomeDeathMessages    文件:TextualComponent.java   
/**
 * Writes the text data represented by this textual component to the specified JSON writer object.
 * A new object within the writer is not started.
 * @param writer The object to which to write the JSON data.
 * @throws IOException If an error occurs while writing to the stream.
 */
public abstract void writeJson(JsonWriter writer) throws IOException;
项目:Ipsum    文件:GsonRaw.java   
/**
 * Return a new {@link com.google.gson.stream.JsonWriter} at the specified {@link java.nio.file.Path} location
 *
 * @param path the location on disk of the file to write to
 * @return the {@link com.google.gson.stream.JsonWriter}
 * @throws java.io.IOException if there was an exception while trying to create the writer
 */
public static JsonWriter writer(Path path) throws IOException {

    return new JsonWriter(Files.newBufferedWriter(path, Charset.defaultCharset()));
}
项目:Ipsum    文件:GsonIO.java   
/**
 * Return a new {@link com.google.gson.stream.JsonWriter} at the specified {@link java.nio.file.Path} location
 *
 * @param path the location on disk of the file to write to
 * @return the {@link com.google.gson.stream.JsonWriter}
 * @throws IOException if there was an exception while trying to create the writer
 */
public static JsonWriter writer(Path path) throws IOException {

    return new JsonWriter(Files.newBufferedWriter(path, Charset.defaultCharset()));
}
项目:EndHQ-Libraries    文件:JsonRepresentedObject.java   
/**
 * Writes the JSON representation of this object to the specified writer.
 * @param writer The JSON writer which will receive the object.
 * @throws IOException If an error occurs writing to the stream.
 */
public void writeJson(JsonWriter writer) throws IOException;
项目:EndHQ-Libraries    文件:TextualComponent.java   
/**
 * Writes the text data represented by this textual component to the specified JSON writer object.
 * A new object within the writer is not started.
 * @param writer The object to which to write the JSON data.
 * @throws IOException If an error occurs while writing to the stream.
 */
public abstract void writeJson(JsonWriter writer) throws IOException;