@NotNull private static JsonWriter writeScope(int frameId, @NotNull JsonWriter writer) throws IOException { // todo: ask vladimir how to simplify this return writer.beginObject() .name("Scope").beginObject() .name("GoroutineID").value(-1) .name("Frame").value(frameId).endObject(); }
@Override protected void writeCustomized(final JsonWriter out, final LiteJobConfiguration value) throws IOException { out.name(MONITOR_EXECUTION).value(value.isMonitorExecution()); out.name(MAX_TIME_DIFF_SECONDS).value(value.getMaxTimeDiffSeconds()); out.name(MONITOR_PORT).value(value.getMonitorPort()); out.name(JOB_SHARDING_STRATEGY_CLASS).value(value.getJobShardingStrategyClass()); out.name(RECONCILE_INTERVAL_MINUTES).value(value.getReconcileIntervalMinutes()); out.name(DISABLED).value(value.isDisabled()); out.name(OVERWRITE).value(value.isOverwrite()); } }
public SetSymbol(@NotNull String symbol, @NotNull String value, int frameId) { try { getWriter().name(PARAMS).beginArray(); writeScope(frameId, getWriter()) .name("Symbol").value(symbol) .name("Value").value(value) .endObject().endArray(); } catch (IOException e) { throw new RuntimeException(e); } }
public class PairAdaptor extends TypeAdapter<Pair> { final Gson embedded = new Gson(); public PairAdaptor() { super(); } @Override public void write(final JsonWriter out, final Pair value) throws IOException { out.beginObject(); out.name("first"); embedded.toJson(embedded.toJsonTree(value.getFirst()), out); out.name("second"); embedded.toJson(embedded.toJsonTree(value.getSecond()), out); out.endObject(); } @Override public Pair read(JsonReader in) throws IOException { throw new UnsupportedOperationException(); } }
/** * Start the generation of meta file. * * @throws IOException if unable to write to meta file (permissions, disk full etc) */ public DataStep startMetaFileGeneration(Instant snapshotInstant) throws IOException { // Compute meta file name. this.snapshotInstant = snapshotInstant; String fileName = MetaFileInfo.getMetaFileName(snapshotInstant); metaFilePath = Paths.get(metaProxy.getLocalMetaFileDirectory().toString(), fileName); Path tempMetaFilePath = Paths.get(metaProxy.getLocalMetaFileDirectory().toString(), fileName + ".tmp"); logger.info("Starting to write a new meta file: {}", metaFilePath); jsonWriter = new JsonWriter(new FileWriter(tempMetaFilePath.toFile())); jsonWriter.beginObject(); jsonWriter.name(MetaFileInfo.META_FILE_INFO); jsonWriter.jsonValue(metaFileInfo.toString()); jsonWriter.name(MetaFileInfo.META_FILE_DATA); jsonWriter.beginArray(); return this; }
private void writeDefaultVector3fData(JsonWriter writer) throws IOException { writer.name("hitNormal"); writer.beginObject(); writer.name("x").value(DEFAULT_DOUBLE_VALUE); writer.name("y").value(DEFAULT_DOUBLE_VALUE); writer.name("z").value(DEFAULT_DOUBLE_VALUE); writer.endObject(); writer.name("hitPosition"); writer.beginObject(); writer.name("x").value(DEFAULT_DOUBLE_VALUE); writer.name("y").value(DEFAULT_DOUBLE_VALUE); writer.name("z").value(DEFAULT_DOUBLE_VALUE); writer.endObject(); writer.name("targetBlockPosition"); writer.beginObject(); writer.name("x").value(DEFAULT_DOUBLE_VALUE); writer.name("y").value(DEFAULT_DOUBLE_VALUE); writer.name("z").value(DEFAULT_DOUBLE_VALUE); writer.endObject(); }
/** * Write a summary to the json document * * @param jsonWriter a {@link com.google.gson.stream.JsonWriter} * used to write the json document */ protected void writeStateSummary(JsonWriter jsonWriter) throws IOException { jsonWriter.name("job name").value(this.getJobName()).name("job id").value(this.getJobId()).name("job state") .value(this.getState().name()).name("start time").value(this.getStartTime()).name("end time") .value(this.getEndTime()).name("duration").value(this.getDuration()).name("tasks").value(this.getTaskCount()) .name("completed tasks").value(this.getCompletedTasks()); }
@SuppressWarnings("unchecked") @Override public void write(JsonWriter out, @Nullable M message) throws IOException { if (message == null) { out.nullValue(); return; } out.beginObject(); for (FieldBinding<M, B> tagBinding : messageAdapter.fieldBindings().values()) { Object value = tagBinding.get(message); if (value == null) { continue; } out.name(tagBinding.name); emitJson(out, value, tagBinding.singleAdapter(), tagBinding.label); } out.endObject(); }
@Override public final void beginArguments() { if (!argumentsObjectStarted) { argumentsObjectStarted = true; if (needObject()) { try { getWriter().name(PARAMS); getWriter().beginArray(); getWriter().beginObject(); } catch (IOException e) { throw new RuntimeException(e); } } } }
/** * Write out an JSON array of vertices. */ private void writeVertices(JsonWriter writer, Set<Vertex> vertices) throws IOException { writer.name("vertices"); writer.beginArray(); for (Vertex vertex: vertices) { writer.beginObject(); writer.name("id").value(vertex.id); writer.name("vertexType").value(vertex.type.name()); writer.name("vertexId").value(vertex.label); writer.endObject(); } writer.endArray(); }
public void write(final JsonWriter out, final MyClass myClassInstance) throws IOException { out.beginObject(); out.name("id").value(myClassInstance.id); out.name("name").value(myClassInstance.name); out.endObject();
@Override public JsonLikeWriter beginObject(String name) throws IOException { blockStack.push(blockType); blockType = BlockType.OBJECT; eventWriter.name(name); eventWriter.beginObject(); return this; }
/** * Example to writeJson using StreamingAPI */ private static void writeJson() throws IOException { OutputStream outputStream = new ByteArrayOutputStream(); JsonWriter writer = new JsonWriter(new OutputStreamWriter(outputStream, "UTF-8")); writer.beginObject(); // main object writer.name("message"); writer.value("Hi"); writer.name("place"); // save object Place writer.beginObject(); writer.name("name"); writer.value("World!"); writer.endObject(); writer.endObject(); writer.close(); System.out.println(outputStream.toString()); // print "{"message":"Hi","place":{"name":"World!"}}" } }
/** * Convert this {@link JobState} to a json document. * * @param jsonWriter a {@link com.google.gson.stream.JsonWriter} * used to write the json document * @param keepConfig whether to keep all configuration properties * @throws IOException */ public void toJson(JsonWriter jsonWriter, boolean keepConfig) throws IOException { jsonWriter.beginObject(); writeStateSummary(jsonWriter); jsonWriter.name("task states"); jsonWriter.beginArray(); for (TaskState taskState : this.taskStates.values()) { taskState.toJson(jsonWriter, keepConfig); } for (TaskState taskState : this.skippedTaskStates.values()) { taskState.toJson(jsonWriter, keepConfig); } jsonWriter.endArray(); if (keepConfig) { jsonWriter.name("properties"); propsToJson(jsonWriter); } jsonWriter.endObject(); }