public static String quoteAndEscape(String str) { return quoteAndEscape(new StringBuilder(), str).toString(); }
private static StringBuilder appendOrd(StringBuilder sb, JsonNode o, int indent) { if (o.isObject()) { return appendObj(sb, o, indent); } else if (o.isArray()) { return appendAry(sb, o, indent); } else if (o.isTextual()) { return quoteAndEscape(sb, o.asText()); } else if (o.isNull() || o.isIntegralNumber() || o.isBoolean()) { return sb.append(String.valueOf(o)); } throw new UnsupportedOperationException(o.getClass().getSimpleName()); }
private static void appendNonNull(StringBuilder builder, String lbl, String value, SessionConfig.PlanFormat format) { if (value != null) { printFieldPrefix(builder, lbl); switch (format) { case JSON: builder.append(value); break; case STRING: JSONUtil.quoteAndEscape(builder, value); break; default: throw new IllegalStateException("Unrecognized plan format: " + format); } printFieldPostfix(builder); } }
private void displayRecord(String result) throws HyracksDataException { String record = result; if (indentJSON) { // TODO(tillw): this is inefficient - do this during record generation try { record = ow.writeValueAsString(om.readValue(result, Object.class)); } catch (IOException e) { // NOSONAR if JSON parsing fails, just use the original string record = result; } } if (conf.fmt() == SessionConfig.OutputFormat.CSV) { // TODO(tillw): this is inefficient as well record = record + "\r\n"; } if (quoteRecord) { // TODO(tillw): this is inefficient as well record = JSONUtil.quoteAndEscape(record); } if (conf.is(SessionConfig.FORMAT_HTML)) { record = ResultUtil.escapeHTML(record); } output.out().print(record); stats.setCount(stats.getCount() + 1); // TODO(tillw) fix this approximation stats.setSize(stats.getSize() + record.length()); }
StringWriter sw = new StringWriter(); appendCSVHeader(sw, recordType); output.out().print(JSONUtil.quoteAndEscape(sw.toString())); output.out().print("\n"); notFirst = true;