/** * Write the contents of the JSONObject as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONObject as JSON text to a writer. For * compactness, no whitespace is added. * <p><b> * Warning: This method assumes that the data structure is acyclical. * </b> * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Make a prettyprinted JSON text of this JSONObject. * <p> * Warning: This method assumes that the data structure is acyclical. * * @param indentFactor * The number of spaces to add to each level of indentation. * @return a printable, displayable, portable, transmittable representation * of the object, beginning with <code>{</code> <small>(left * brace)</small> and ending with <code>}</code> <small>(right * brace)</small>. * @throws JSONException * If the object contains an invalid number. */ public String toString(int indentFactor) throws JSONException { StringWriter w = new StringWriter(); synchronized (w.getBuffer()) { return this.write(w, indentFactor, 0).toString(); } }
StringWriter w = new StringWriter(); synchronized (w.getBuffer()) { return this.write(w, indentFactor, 0).toString();
private JsonCapsuleFactory(JSONObject jo) { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); GZIPOutputStream out = null; try {out = new GZIPOutputStream(baos, 1024){{def.setLevel(Deflater.BEST_COMPRESSION);}};} catch (IOException e) {} OutputStreamWriter osw = new OutputStreamWriter(out); jo.write(osw); try {osw.close();} catch (IOException e) {} //byte[] b = new ObjectMapper().writer().writeValueAsBytes(json); //byte[] c = Compression.gzip(b); byte[] c = baos.toByteArray(); //if (b.length <= c.length) { // this.capsule = new byte[b.length + 1]; // this.capsule[0] = 0; // System.arraycopy(b, 0, this.capsule, 1, b.length); //} else { this.capsule = new byte[c.length + 1]; this.capsule[0] = 1; System.arraycopy(c, 0, this.capsule, 1, c.length); //} //System.out.print("DEBUG " + this.getRawJson()); }
writer.write("null"); } else if (value instanceof JSONObject) { ((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { new JSONObject((Map<String, Object>) value).write(writer, indentFactor, indent); } else if (value instanceof Collection) { new JSONArray((Collection<Object>) value).write(writer, indentFactor,
writer.write(quote(((Enum<?>)value).name())); } else if (value instanceof JSONObject) { ((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { Map<?, ?> map = (Map<?, ?>) value; new JSONObject(map).write(writer, indentFactor, indent); } else if (value instanceof Collection) { Collection<?> coll = (Collection<?>) value;
/** * Write the contents of the JSONObject as JSON text to a writer. For * compactness, no whitespace is added. * <p><b> * Warning: This method assumes that the data structure is acyclical. * </b> * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
@Override public void writeToWriter(Object model, Writer writer) throws Exception { ((JSONObject)model).write(writer); }
StringWriter w = new StringWriter(); synchronized (w.getBuffer()) { return this.write(w, indentFactor, 0).toString();
writer.write(quote(((Enum<?>)value).name())); } else if (value instanceof JSONObject) { ((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { Map<?, ?> map = (Map<?, ?>) value; new JSONObject(map).write(writer, indentFactor, indent); } else if (value instanceof Collection) { Collection<?> coll = (Collection<?>) value;
/** * Write the contents of the JSONObject as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONObject as JSON text to a writer. * For compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONObject as JSON text to a writer. * For compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONObject as JSON text to a writer. * For compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
private static void write(OutputStream outputStream, JSONObject json) { logger.debug("Returning {} response", json.get(STATUS_CODE)); if (logger.isTraceEnabled()) { logger.trace("Response: {}", json); } try (OutputStreamWriter writer = new OutputStreamWriter(outputStream, Charsets.UTF_8)) { json.write(writer); } catch (IOException e) { logger.debug("Error while closing output response"); } }
private void sendJsonResponse(HttpServletResponse response, JSONObject result) throws Exception { response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", (new Date()).getTime()); response.setContentType("text/plain"); response.setCharacterEncoding("utf-8"); OutputStreamWriter osw = new OutputStreamWriter( response.getOutputStream(), "UTF-8" ); result.write(osw); osw.flush(); }
public static void writeReportsToWriter(Collection<CheckReport> reports, Writer writer) throws IOException, JSONException { JSONArray jsonReports = reportsToJSON(reports); JSONObject rootObj = new JSONObject(); rootObj.put(KEY_REPORTS, jsonReports); rootObj.write(writer, 2, 0); writer.flush(); }
/** * Writes the measuremnt to the {@link #repositoryPath}. */ private void write(JSONObject jsonMeasurement) { try { jsonMeasurement.write(this.getWriter()); writer.write('\n'); } catch (IOException e) { IOUtils.closeQuietly(this.writer); throw new RuntimeException("Could not open cardinality repository file for writing.", e); } }
/** * Writes the measuremnt to the {@link #repositoryPath}. */ private void write(JSONObject jsonMeasurement) throws IOException { jsonMeasurement.write(this.getWriter()); writer.write('\n'); }