Refine search
/** * Reconfigures this JsonEncoder to output to the JsonGenerator provided. * <p/> * If the JsonGenerator provided is null, a NullPointerException is thrown. * <p/> * Otherwise, this JsonEncoder will flush its current output and then * reconfigure its output to use the provided JsonGenerator. * * @param generator * The JsonGenerator to direct output to. Cannot be null. * @throws IOException * @return this JsonEncoder */ private JsonEncoder configure(JsonGenerator generator) throws IOException { if (null == generator) throw new NullPointerException("JsonGenerator cannot be null"); if (null != parser) { flush(); } this.out = generator; return this; }
/** * Creates a {@link JsonEncoder} using the OutputStream provided for writing * data conforming to the Schema provided. * <p/> * {@link JsonEncoder} buffers its output. Data may not appear on the * underlying OutputStream until {@link Encoder#flush()} is called. * <p/> * {@link JsonEncoder} is not thread-safe. * * @param schema * The Schema for data written to this JsonEncoder. Cannot be null. * @param out * The OutputStream to write to. Cannot be null. * @return A JsonEncoder configured with <i>out</i> and <i>schema</i> * @throws IOException */ public JsonEncoder jsonEncoder(Schema schema, OutputStream out) throws IOException { return new JsonEncoder(schema, out); }
/** * Reconfigures this JsonEncoder to use the output stream provided. * <p/> * If the OutputStream provided is null, a NullPointerException is thrown. * <p/> * Otherwise, this JsonEncoder will flush its current output and then * reconfigure its output to use a default UTF8 JsonGenerator that writes * to the provided OutputStream. * * @param out * The OutputStream to direct output to. Cannot be null. * @throws IOException * @return this JsonEncoder */ public JsonEncoder configure(OutputStream out) throws IOException { this.configure(getJsonGenerator(out, false)); return this; }
@Override public void writeMapStart() throws IOException { push(); isEmpty.set(depth()); parser.advance(Symbol.MAP_START); out.writeStartObject(); }
private void dumpJson(PrintStream out, Schema schema, Object datum) throws IOException { DatumWriter<Object> writer = new GenericDatumWriter<Object>(schema); JsonGenerator g = new JsonFactory().createJsonGenerator(out, JsonEncoding.UTF8); g.useDefaultPrettyPrinter(); writer.write(datum, new JsonEncoder(schema, g)); g.flush(); out.println(); out.flush(); }
@Override public void writeMapEnd() throws IOException { if (! isEmpty.get(pos)) { parser.advance(Symbol.ITEM_END); } pop(); parser.advance(Symbol.MAP_END); out.writeEndObject(); }
@Override public void writeArrayEnd() throws IOException { if (! isEmpty.get(pos)) { parser.advance(Symbol.ITEM_END); } pop(); parser.advance(Symbol.ARRAY_END); out.writeEndArray(); }
@Override public void writeArrayStart() throws IOException { parser.advance(Symbol.ARRAY_START); out.writeStartArray(); push(); isEmpty.set(depth()); }
JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator( out, JsonEncoding.UTF8); JsonEncoder jsonEncoder = new JsonEncoder(message.getRequest(), jsonGenerator); jsonGenerator.flush(); jsonEncoder.flush(); out.flush(); } catch (IOException e) {
@Override public void init(OutputStream out) throws IOException { flush(); this.out = getJsonGenerator(out); }
JsonEncoder(Schema sc, OutputStream out, boolean pretty) throws IOException { this(sc, getJsonGenerator(out, pretty)); }
JsonEncoder(Schema sc, JsonGenerator out) throws IOException { configure(out); this.parser = new Parser(new JsonGrammarGenerator().generate(sc), this); }
@Override public void startItem() throws IOException { if (! isEmpty.get(pos)) { parser.advance(Symbol.ITEM_END); } super.startItem(); isEmpty.clear(depth()); }
@Override public void writeArrayEnd() throws IOException { if (! isEmpty.get(pos)) { parser.advance(Symbol.ITEM_END); } pop(); parser.advance(Symbol.ARRAY_END); out.writeEndArray(); }
private void dumpJson(PrintStream out, Schema schema, Object datum) throws IOException { DatumWriter<Object> writer = new GenericDatumWriter<Object>(schema); JsonGenerator g = new JsonFactory().createJsonGenerator(out, JsonEncoding.UTF8); g.useDefaultPrettyPrinter(); writer.write(datum, new JsonEncoder(schema, g)); g.flush(); out.println(); out.flush(); }
@Override public void writeMapStart() throws IOException { push(); isEmpty.set(depth()); parser.advance(Symbol.MAP_START); out.writeStartObject(); }
@Override public void writeMapEnd() throws IOException { if (! isEmpty.get(pos)) { parser.advance(Symbol.ITEM_END); } pop(); parser.advance(Symbol.MAP_END); out.writeEndObject(); }
@Override public void writeArrayEnd() throws IOException { if (! isEmpty.get(pos)) { parser.advance(Symbol.ITEM_END); } pop(); parser.advance(Symbol.ARRAY_END); out.writeEndArray(); }