/** * This is a helper method which creates a JsonGenerator instance, for writing * the state of the ClusterManager to the state file. The JsonGenerator * instance writes to a compressed file if we have the compression flag * turned on. * * @param conf The CoronaConf instance to be used * @return The JsonGenerator instance to be used * @throws IOException */ public static JsonGenerator createJsonGenerator(CoronaConf conf) throws IOException { OutputStream outputStream = new FileOutputStream(conf.getCMStateFile()); if (conf.getCMCompressStateFlag()) { outputStream = new GZIPOutputStream(outputStream); } ObjectMapper mapper = new ObjectMapper(); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(outputStream, JsonEncoding.UTF8); jsonGenerator.setCodec(mapper); if (!conf.getCMCompressStateFlag()) { jsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter()); } return jsonGenerator; }
private void enableDisableJSONGeneratorFeature(JsonGenerator jg) { jg.enable(Feature.ESCAPE_NON_ASCII); jg.disable(Feature.AUTO_CLOSE_TARGET); jg.setPrettyPrinter(new DefaultPrettyPrinter()); if(PDXTOJJSON_UNQUOTEFIELDNAMES) jg.disable(Feature.QUOTE_FIELD_NAMES); }
public JSONMeasurementsExporter(OutputStream os) throws IOException { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os)); g = factory.createJsonGenerator(bw); g.setPrettyPrinter(new DefaultPrettyPrinter()); }
public void serialize(Object obj, Writer out) { try { JsonGenerator gen = this.factory.createJsonGenerator(out); gen.setPrettyPrinter(new DefaultPrettyPrinter()); gen.writeObject(obj); gen.flush(); out.flush(); } catch (IOException e) { throw new JsonException(e); } }