Streams from a json reader to a json writer and performs pretty printing.

This function is copied from https://sites.google.com/site/gson/streaming

@param reader json reader
@param writer json writer
@throws IOException thrown if the json is malformed
432517
private static void prettyPrint(JsonReader reader, JsonWriter writer) throws IOException {
        writer.setIndent("  ");
        while (true) {
            final JsonToken token = reader.peek();
            switch (token) {
                case BEGIN_ARRAY:
                    reader.beginArray();
                    writer.beginArray();
                    break;
                case END_ARRAY:
                    reader.endArray();
                    writer.endArray();
                    break;
                case BEGIN_OBJECT:
                    reader.beginObject();
                    writer.beginObject();
                    break;
                case END_OBJECT:
                    reader.endObject();
                    writer.endObject();
                    break;
                case NAME:
                    final String name = reader.nextName();
                    writer.name(name);
                    break;
                case STRING:
                    final String s = reader.nextString();
                    writer.value(s);
                    break;
                case NUMBER:
                    final String n = reader.nextString();
                    writer.value(new BigDecimal(n));
                    break;
                case BOOLEAN:
                    final boolean b = reader.nextBoolean();
                    writer.value(b);
                    break;
                case NULL:
                    reader.nextNull();
                    writer.nullValue();
                    break;
                case END_DOCUMENT:
                    return;
                default:
                    LOGGER.debug("Unexpected JSON toekn {}", token.toString());
                    break;
            }
        }
    }
1302669
public static void writeJSON(Map<String, ? extends Object> map, Appendable out, JSONStyle compression)
			throws IOException {
		if (map == null) {
			out.append("null");
			return;
		}
		JsonWriter.JSONMapWriter.writeJSONString(map, out, compression);
	}
1034076
public static void write(JsonElement element, JsonWriter writer) throws IOException {
    TypeAdapters.JSON_ELEMENT.write(writer, element);
  }
1179606
private void readFromStream(InputStream in) throws IOException {
        document = DocumentFactory.newDocument(Json.read(in));
    }
293082
public Writer write(Writer writer) throws JSONException {
    try {
      boolean b = false;
      int len = length();

      writer.write('[');

      for (int i = 0; i < len; i += 1) {
        if (b) {
          writer.write(',');
        }
        Object v = this.myArrayList.get(i);
        if (v instanceof JSONObject) {
          ((JSONObject) v).write(writer);
        } else if (v instanceof JSONArray) {
          ((JSONArray) v).write(writer);
        } else {
          writer.write(JSONObject.valueToString(v));
        }
        b = true;
      }
      writer.write(']');
      return writer;
    } catch (IOException e) {
      throw new JSONException(e);
    }
  }
118535
public static void writeToOutputStream(String s, OutputStream output, String encoding) throws IOException {
		BufferedReader reader = new BufferedReader(new StringReader(s));
		PrintStream writer;
		if (encoding != null) {
			writer = new PrintStream(output, true, encoding);
		}
		else {
			writer = new PrintStream(output, true);
		}
		String line;
		while ((line = reader.readLine()) != null) {
			writer.println(line);
		}
	}
697993
public static void copy(InputStream input, Writer writer) throws IOException {
		copy(new InputStreamReader(input), writer);
	}
693154
public void write(JsonGenerator jsonGenerator) throws IOException {
    jsonGenerator.writeStartObject();
    // retiredSessions and numRetiredSessions need not be persisted

    // sessionCounter can be set to 0, when the SessionManager is instantiated

    // sessions begins
    jsonGenerator.writeFieldName("sessions");
    jsonGenerator.writeStartObject();
    for (String sessionId : sessions.keySet()) {
      jsonGenerator.writeFieldName(sessionId);
      sessions.get(sessionId).write(jsonGenerator);
    }
    jsonGenerator.writeEndObject();
    // sessions ends

    jsonGenerator.writeNumberField("sessionCounter",
                                    sessionCounter.longValue());

    jsonGenerator.writeEndObject();

    // We can rebuild runnableSessions
    // No need to write startTime and numRetiredSessions
  }
947868
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
        jsonObject = Utils.mapper().readValue((DataInput) stream, ObjectNode.class);
    }
1277645
@Override
    protected void write(JsonGenerator g, JacksonJrsTreeCodec codec) throws IOException {
        g.writeString(_value);
    }
646685
public void write(JsonGenerator jsonGenerator) throws IOException {
    jsonGenerator.writeStartObject();

    // nameToNode begins
    jsonGenerator.writeFieldName("nameToNode");
    jsonGenerator.writeStartObject();
    for (Map.Entry<String, ClusterNode> entry : nameToNode.entrySet()) {
      jsonGenerator.writeFieldName(entry.getKey());
      entry.getValue().write(jsonGenerator);
    }
    jsonGenerator.writeEndObject();
    // nameToNode ends

    // hostsToSessions begins
    // We create a new Map of type <ClusterNode.name, Set<SessionIds>>.
    // The original hostsToSessions map has the ClusterNode as its key, and
    // we do not need to persist the entire ClusterNode again, since we have
    // already done that with nameToNode.
    Map<String, Set<String>> hostsToSessionsMap =
      new HashMap<String, Set<String>>();
    for (Map.Entry<ClusterNode, Set<String>> entry :
      hostsToSessions.entrySet()) {
      hostsToSessionsMap.put(entry.getKey().getName(),
        entry.getValue());
    }
    jsonGenerator.writeObjectField("hostsToSessions", hostsToSessionsMap);
    // hostsToSessions ends

    jsonGenerator.writeObjectField("nameToApps", nameToApps);

    // faultManager is not required

    // We can rebuild the loadManager
    jsonGenerator.writeEndObject();
  }
59198
public void writeToStream(OutputStream stream, Object object) throws SerializationException {
        try {
            mapper.writeValue(stream, object);
        } catch (IOException ex) {
            throw new SerializationException("Exception during serialization", ex);
        }
    }
483069
public void write(JsonGenerator jsonGenerator) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("poolGroupName", poolGroupName);
    jsonGenerator.writeStringField("poolName", poolName);
    jsonGenerator.writeEndObject();
  }
1275102
@Override
  public void write(JsonWriter out, WordTiming wordTiming) throws IOException {
    out.beginArray();

    out.value(wordTiming.getWord());
    out.value(wordTiming.getStartTime());
    out.value(wordTiming.getEndTime());

    out.endArray();
    out.flush();
  }
721600
protected void write(Writer writer, WritingVisitor visitor) throws IOException {
      if( isNullObject() ){
         writer.write(JSONNull.getInstance().toString());
      }

      boolean b = false;
      Iterator keys = visitor.keySet(this).iterator();
      writer.write('{');

      while( keys.hasNext() ){
         if( b ){
            writer.write(',');
         }
         Object k = keys.next();
         writer.write(JSONUtils.quote(k.toString()));
         writer.write(':');
         Object v = this.properties.get(k);
         if( v instanceof JSON ){
            visitor.on((JSON) v, writer);
         }else{
            visitor.on(v, writer);
         }
         b = true;
      }
      writer.write('}');
   }
723602
public static void json(Object obj, final String[] properties,
                            Writer writer, boolean writeClass,
                            Converter<Object, Map<String, Object>> mc) throws IOException {
        if (obj == null)
            writer.write(NULL);
        else
            json(obj, properties, new JSONWriter(writer), writeClass, mc);
    }
557255
@Override
    public void writeValue(JsonGenerator g, Object value) throws IOException {
        write(value, g);
    }