@Override void write(JsonWriter writer) throws IOException { writer.writeArrayOpen(); Iterator<JsonValue> iterator = iterator(); if (iterator.hasNext()) { iterator.next().write(writer); while (iterator.hasNext()) { writer.writeArraySeparator(); iterator.next().write(writer); } } writer.writeArrayClose(); }
@Override void write(JsonWriter writer) throws IOException { writer.writeObjectOpen(); Iterator<String> namesIterator = names.iterator(); Iterator<JsonValue> valuesIterator = values.iterator(); if (namesIterator.hasNext()) { writer.writeMemberName(namesIterator.next()); writer.writeMemberSeparator(); valuesIterator.next().write(writer); while (namesIterator.hasNext()) { writer.writeObjectSeparator(); writer.writeMemberName(namesIterator.next()); writer.writeMemberSeparator(); valuesIterator.next().write(writer); } } writer.writeObjectClose(); }
/** * Writes the JSON representation of this value to the given writer using the given formatting. * <p> * Writing performance can be improved by using a {@link java.io.BufferedWriter BufferedWriter}. * </p> * * @param writer * the writer to write this value to * @param config * a configuration that controls the formatting or <code>null</code> for the minimal form * @throws IOException * if an I/O error occurs in the writer */ public void writeTo(Writer writer, WriterConfig config) throws IOException { if (writer == null) { throw new NullPointerException("writer is null"); } if (config == null) { throw new NullPointerException("config is null"); } WritingBuffer buffer = new WritingBuffer(writer, 128); write(config.createWriter(buffer)); buffer.flush(); }
/** * Writes the JSON representation for this object to the given writer. * <p> * Single elements are passed directly to the given writer. Therefore, if the writer is not * buffered, wrapping it in a {@link java.io.BufferedWriter BufferedWriter} can drastically * improve writing performance. * </p> * * @param writer * the writer to write this value to * @throws IOException * if an I/O error occurs in the writer */ public void writeTo( Writer writer ) throws IOException { write( new JsonWriter( writer ) ); }
/** * Returns the JSON string for this value in its minimal form, without any additional whitespace. * The result is guaranteed to be a valid input for the method {@link #readFrom(String)} and to * create a value that is <em>equal</em> to this object. * * @return a JSON string that represents this value */ @Override public String toString() { StringWriter stringWriter = new StringWriter(); JsonWriter jsonWriter = new JsonWriter( stringWriter ); try { write( jsonWriter ); } catch( IOException exception ) { // StringWriter does not throw IOExceptions throw new RuntimeException( exception ); } return stringWriter.toString(); }
@Override void write(JsonWriter writer) throws IOException { writer.writeArrayOpen(); Iterator<JsonValue> iterator = iterator(); if (iterator.hasNext()) { iterator.next().write(writer); while (iterator.hasNext()) { writer.writeArraySeparator(); iterator.next().write(writer); } } writer.writeArrayClose(); }
@Override void write(JsonWriter writer) throws IOException { writer.writeArrayOpen(); Iterator<JsonValue> iterator = iterator(); if (iterator.hasNext()) { iterator.next().write(writer); while (iterator.hasNext()) { writer.writeArraySeparator(); iterator.next().write(writer); } } writer.writeArrayClose(); }
@Override void write(JsonWriter writer) throws IOException { writer.writeObjectOpen(); Iterator<String> namesIterator = names.iterator(); Iterator<JsonValue> valuesIterator = values.iterator(); if (namesIterator.hasNext()) { writer.writeMemberName(namesIterator.next()); writer.writeMemberSeparator(); valuesIterator.next().write(writer); while (namesIterator.hasNext()) { writer.writeObjectSeparator(); writer.writeMemberName(namesIterator.next()); writer.writeMemberSeparator(); valuesIterator.next().write(writer); } } writer.writeObjectClose(); }
@Override void write(JsonWriter writer) throws IOException { writer.writeObjectOpen(); Iterator<String> namesIterator = names.iterator(); Iterator<JsonValue> valuesIterator = values.iterator(); if (namesIterator.hasNext()) { writer.writeMemberName(namesIterator.next()); writer.writeMemberSeparator(); valuesIterator.next().write(writer); while (namesIterator.hasNext()) { writer.writeObjectSeparator(); writer.writeMemberName(namesIterator.next()); writer.writeMemberSeparator(); valuesIterator.next().write(writer); } } writer.writeObjectClose(); }
/** * Writes the JSON representation of this value to the given writer using the given formatting. * <p> * Writing performance can be improved by using a {@link java.io.BufferedWriter BufferedWriter}. * </p> * * @param writer * the writer to write this value to * @param config * a configuration that controls the formatting or <code>null</code> for the minimal form * @throws IOException * if an I/O error occurs in the writer */ public void writeTo(Writer writer, WriterConfig config) throws IOException { if (writer == null) { throw new NullPointerException("writer is null"); } if (config == null) { throw new NullPointerException("config is null"); } WritingBuffer buffer = new WritingBuffer(writer, 128); write(config.createWriter(buffer)); buffer.flush(); }
protected void writeArray( JsonArray array ) throws IOException { writeBeginArray(); boolean first = true; for( JsonValue value : array ) { if( !first ) { writeArrayValueSeparator(); } value.write( this ); first = false; } writeEndArray(); }
/** * Writes the JSON representation of this value to the given writer using the given formatting. * <p> * Writing performance can be improved by using a {@link java.io.BufferedWriter BufferedWriter}. * </p> * * @param writer * the writer to write this value to * @param config * a configuration that controls the formatting or <code>null</code> for the minimal form * @throws IOException * if an I/O error occurs in the writer */ public void writeTo(Writer writer, WriterConfig config) throws IOException { if (writer == null) { throw new NullPointerException("writer is null"); } if (config == null) { throw new NullPointerException("config is null"); } WritingBuffer buffer = new WritingBuffer(writer, 128); write(config.createWriter(buffer)); buffer.flush(); }
protected void writeObject( JsonObject object ) throws IOException { writeBeginObject(); boolean first = true; for( JsonObject.Member member : object ) { if( !first ) { writeObjectValueSeparator(); } writeString( member.getName() ); writeNameValueSeparator(); member.getValue().write( this ); first = false; } writeEndObject(); }