Print JSON.
@param src Source
@return JSON
@throws IOException If fails
327083
private static byte[] print(final RsJson.Source src) throws IOException {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (JsonWriter writer = Json.createWriter(baos)) {
            writer.write(src.toJson());
        }
        return baos.toByteArray();
    }
1269222
protected void writeJSON(final HttpServletResponse resp, final Object obj)
      throws IOException {
    writeJSON(resp, obj, false);
  }
854808
public static HttpResponse putJson(String urlStr, String body) throws IOException {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "application/json");
        return put(urlStr, body, headers);
    }
1045182
@SuppressWarnings("static-method")
	protected String generateJson(Map<String, Object> map) throws JsonProcessingException {
		final ObjectMapper mapper = new ObjectMapper();
		return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
	}
188436
public static String convertToJson(Node node) throws IOException {
        try (StringWriter writer = new StringWriter(); JsonGenerator generator = new JsonFactory().createGenerator(writer)) {
            convertToJson(node, generator, name -> name);
            return writer.toString();
        }
    }
1003468
@SuppressWarnings({"unchecked"})
    public <T> T read(InputStream jsonInputStream) throws IOException {
        return read(jsonInputStream, Configuration.defaultConfiguration());
    }
1259434
private static void generateJson(CellScanner cellScanner, Function<Bytes, String> encoder,
      PrintStream out) throws JsonIOException {
    Gson gson = new GsonBuilder().serializeNulls().setDateFormat(DateFormat.LONG)
        .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setVersion(1.0)
        .create();

    Map<String, String> json = new LinkedHashMap<>();
    for (RowColumnValue rcv : cellScanner) {
      json.put(FLUO_ROW, encoder.apply(rcv.getRow()));
      json.put(FLUO_COLUMN_FAMILY, encoder.apply(rcv.getColumn().getFamily()));
      json.put(FLUO_COLUMN_QUALIFIER, encoder.apply(rcv.getColumn().getQualifier()));
      json.put(FLUO_COLUMN_VISIBILITY, encoder.apply(rcv.getColumn().getVisibility()));
      json.put(FLUO_VALUE, encoder.apply(rcv.getValue()));
      gson.toJson(json, out);
      out.append("\n");

      if (out.checkError()) {
        break;
      }
    }
    out.flush();
  }
648102
protected static final Object parseList(Source src) throws IOException {
		final LinkedList<Object> list = new LinkedList<Object>();
		boolean foundEnd = false;
		try {
			if (src.ch == '[') {
				src.idx++;
			}
			skipWhitespaces(src);
			if (src.ch == ']') {
				src.idx++;
				return list;
			}
			char c;
			loop: while (src.idx < src.last) {
				list.add(parseNext(src));
				while (true) {
					c = src.chars[src.idx];
					if (c == ',') {
						src.idx++;
						continue loop;
					}
					if (c == ']') {
						foundEnd = true;
						src.idx++;
						break loop;
					}
					if (c <= 32) {
						src.idx++;
						continue;
					}
					break;
				}
				c = src.chars[src.idx];
				if (c == ',') {
					src.idx++;
					continue;
				}
				if (c == ']') {
					src.idx++;
					foundEnd = true;
					break;
				}
				throw new IOException(String.format(
						"Expecting a ',' or a ']', " + " but got ch character of  %s " + " on array idx of %s!",
						(int) c, list.size()));
			}
		} catch (IOException ioCause) {
			throw ioCause;
		} catch (Exception cause) {
			throw new IOException("Issue parsing JSON array!", cause);
		}
		if (!foundEnd) {
			throw new IOException("Did not find end of JSON Array!");
		}
		return list;
	}
1239025
public static JSONArray copy(final JSONArray src) {
        final JSONArray dest = new JSONArray();
        final int len = src.length();
        for (int i = 0; i < len; ++i) {
            dest.put(src.opt(i));
        }
        return dest;
    }
711936
public static void printJsonCodePoint(Appendable out, int codePoint)
        throws IOException
    {
        // JSON only allows double-quote strings.
        printCodePoint(out, codePoint, EscapeMode.JSON);
    }
585362
public static void writeJson(Serializable serializable, OutputStream output)
			throws IOException {
		TransportFormat.JSON.writeSerializableTo(serializable, output);
	}
1341551
@Path("print")
    @GET
    @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
    @SuppressWarnings("checkstyle:illegalcatch")
    public Response print(@QueryParam("origin") final String _origin,
                          @QueryParam("stmt") final String _stmt)
    {
        Response ret = null;
        // only permit print on this url
        try {
            final EQLInvoker invoker = InvokerUtil.getInvoker();
            final IEQLStmt stmt = invoker.invoke(_stmt);
            if (invoker.getSyntaxErrors().isEmpty() && stmt instanceof IPrintStmt) {
                registerEQLStmt(_origin, _stmt);
                final DataList datalist = JSONData.getDataList((IPrintStmt) stmt);
                ret = Response.ok().type(MediaType.APPLICATION_JSON).entity(getJSONReply(datalist)).build();
            } else if (invoker.getSyntaxErrors().isEmpty() && stmt instanceof ICIPrintStmt) {
                registerEQLStmt(_origin, _stmt);
                final AbstractCI<?> ci = JSONCI.getCI((ICIPrintStmt) stmt);
                ret = Response.ok().type(MediaType.APPLICATION_JSON).entity(getJSONReply(ci)).build();
            } else {
                final StringBuilder error = new StringBuilder();
                for (final String syntaxError : invoker.getSyntaxErrors()) {
                    LOG.warn(syntaxError);
                    error.append(syntaxError).append("\n");
                }
                final ErrorReply reply = new ErrorReply()
                                .setError("EQL Syntax Error")
                                .setMessage(error.toString());
                ret = Response.serverError().type(MediaType.APPLICATION_JSON).entity(getJSONReply(reply)).build();
            }
        } catch (final Exception e) {
            LOG.error("Error processing data.", e);
            final ErrorReply reply = new ErrorReply()
                            .setError(e.getClass().getName())
                            .setMessage(e.getMessage())
                            .setStacktrace(ExceptionUtils.getStackTrace(e));
            ret = Response.serverError().type(MediaType.APPLICATION_JSON).entity(getJSONReply(reply)).build();
        }
        return ret;
    }
949114
public void println(final String str) throws IOException {
        this.writer.print(str);
        this.writer.print("\r\n");
        this.writer.flush();
    }
52449
public String postJson(String endpoint, JSONObject json) throws IOException {
        return this.postJson(endpoint, "", json);
    }
838996
protected void returnJsonSystemError(HttpServletRequest request, HttpServletResponse response,
            ResultCode resultCode) throws IOException {
        Map<String, Object> errors = new HashMap<String, Object>();
        errors.put(WebResponseConstant.MESSAGE_GLOBAL, resultCode.getMessage().getMessage());
        JsonObject<?> json = JsonObject.create();
        json.setStatus(resultCode.getCode());
        json.setStatusInfo(errors);
        response.setContentType("application/json; charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(JsonUtils.toJson(json));
    }
879176
public static HttpResponse getJson(String urlStr) throws IOException {
        URL url = new URL(urlStr);
        HttpURLConnection urlConnection = (HttpURLConnection) url
                .openConnection();
        urlConnection.addRequestProperty("Accept", "application/json");

        BufferedReader in = null;
        try {
            int errorCode = urlConnection.getResponseCode();
            if ((errorCode <= 202) && (errorCode >= 200)) {
                in = new BufferedReader(new InputStreamReader(
                        urlConnection.getInputStream()));
            } else {
                InputStream error = urlConnection.getErrorStream();
                if (error != null) {
                    in = new BufferedReader(new InputStreamReader(error));
                }
            }

            String json = null;
            if(in != null){
                json = CharStreams.toString(in);
            }
            return new HttpResponse(errorCode, json);
        } finally {
            if(in != null){
                in.close();
            }
        }
    }
492998
public JSONObject instantiateJsonObject(InputStream in) throws IOException,
                                                                JSONException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer contents = new StringBuffer();
    String text = null;
    while ((text = reader.readLine()) != null) {
      contents.append(text).append(System.getProperty("line.separator"));
    }
    in.close();
    JSONObject json = new JSONObject(contents.toString());
    return json;
  }