@Override public void flush() throws IOException { json.flush(); }
public void cleanup() { if(writer != null) { try { writer.writeEnd(); writer.flush(); } catch(JsonException jex) { log.warn("JsonException in cleanup()", jex); } } writer = null; }
public String generateJson() { StringWriter w = new StringWriter(); javax.json.stream.JsonGenerator gen = factory.createGenerator(w); generatedValues = new LinkedHashMap<>(); processProperties(gen, config, ""); gen.flush(); return w.toString(); }
@Override public Generator end() { generator.writeEnd(); // end record generator.flush(); generator.close(); return this; }
@Override public void flush() throws IOException { try { generator.flush(); } catch (JsonException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw e; } } }
private static JsonObject toAttributesObject(Attributes targetSeriesAttrs) { StringWriter strWriter = new StringWriter(); JsonGenerator gen = Json.createGenerator(strWriter); JSONWriter writer = new JSONWriter(gen); writer.write(targetSeriesAttrs); gen.flush(); gen.close(); return Json.createReader(new StringReader(strWriter.toString())) .readObject(); }
private void renderJson(final SlingHttpServletResponse response, final Map<String, String> data) throws IOException { // render data in JSON format response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); final Writer out = response.getWriter(); //deliberately not closing, as that closes the response out. final JsonGenerator w = Json.createGenerator(out); w.writeStartObject(); for (final Map.Entry<String, String> e : data.entrySet()) { w.write(e.getKey(), e.getValue()); } w.writeEnd(); w.flush(); }
private static void writeJSON(Writer stream, DocumentRoot<QName> document) throws CoreIoException { HashMap<String, Object> config = new HashMap<>(); config.put(JsonGenerator.PRETTY_PRINTING, true); JsonGenerator writer = Json.createGeneratorFactory(config).createGenerator(stream); JsonIo jsonIo = new JsonIo(); jsonIo.createIoWriter(writer).write(StringifyQName.qname2string.mapDR(document)); writer.flush(); writer.close(); }
private static void writeJSON(Writer stream, DocumentRoot<QName> document) throws CoreIoException { HashMap<String, Object> config = new HashMap<>(); config.put(JsonGenerator.PRETTY_PRINTING, true); JsonGenerator writer = Json.createGeneratorFactory(config).createGenerator(stream); JsonIo jsonIo = new JsonIo(); jsonIo.createIoWriter(writer).write(StringifyQName.qname2string.mapDR(document)); writer.flush(); writer.close(); }
private static void write(Writer stream, DocumentRoot<QName> document) throws Exception { Map<String, Object> config = new HashMap<>(); config.put(JsonGenerator.PRETTY_PRINTING, true); JsonGenerator writer = Json.createGeneratorFactory(config).createGenerator(stream); JsonIo jsonIo = new JsonIo(); jsonIo.createIoWriter(writer).write(StringifyQName.qname2string.mapDR(document)); writer.flush(); writer.close(); }
/** * Answer a JSON representation of a recorded query * @param query * @return */ public String toJSON(RecordedQuery query) { StringWriter sw = new StringWriter(); JsonGenerator generator; if (this.prettyFormat != Format.NONE) { JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory(); generator = gf.createGenerator(sw); } else generator = Json.createGenerator(sw); generator.writeStartObject(); writeQuery(query, generator); generator.writeEnd(); generator.flush(); return sw.toString(); }
/** * Answer a JSON representation of a recorded query * @param query * @return */ public String toJSON(RecordedQuery query) { StringWriter sw = new StringWriter(); JsonGenerator generator; if (this.prettyFormat != Format.NONE) { JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory(); generator = gf.createGenerator(sw); } else generator = Json.createGenerator(sw); generator.writeStartObject(); writeQuery(query, generator); generator.writeEnd(); generator.flush(); return sw.toString(); }
/** * Answer a JSON representation of the available domains in the database * @return */ public String getDomains() { StringWriter sw = new StringWriter(); JsonGenerator generator; if (this.prettyFormat != Format.NONE) { JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory(); generator = gf.createGenerator(sw); } else generator = Json.createGenerator(sw); generator.writeStartArray(); List<String> doms = DomainInformation.availableDomains(dbAccess); for (String dom : doms) { generator.write(dom); } generator.writeEnd(); generator.flush(); return sw.toString(); }
/** * Answer a JSON object containing the domain name * @return */ public String getDomainName() { DomainModel model = ((IIntDomainAccess)this.domainAccess).getInternalDomainAccess().getDomainModel(); StringWriter sw = new StringWriter(); JsonGenerator generator; if (this.prettyFormat != Format.NONE) { JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory(); generator = gf.createGenerator(sw); } else generator = Json.createGenerator(sw); generator.writeStartObject(); generator.write("domainName", model.getDomainName()); generator.writeEnd(); generator.flush(); return sw.toString(); }
/** * Answer a JSON representation of the domain model * @return */ public String getDomainModel() { DomainModel model = ((IIntDomainAccess)this.domainAccess).getInternalDomainAccess().getDomainModel(); StringWriter sw = new StringWriter(); JsonGenerator generator; if (this.prettyFormat != Format.NONE) { JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory(); generator = gf.createGenerator(sw); } else generator = Json.createGenerator(sw); generator.writeStartObject(); generator.write("domainName", model.getDomainName()); writeModel(model, generator); generator.writeEnd(); generator.flush(); return sw.toString(); }
/** * Answer a JSON representation of the domain model * @return */ public String getDomainModel() { DomainModel model = ((IIntDomainAccess)this.domainAccess).getInternalDomainAccess().getDomainModel(); StringWriter sw = new StringWriter(); JsonGenerator generator; if (this.prettyFormat != Format.NONE) { JsonGeneratorFactory gf = JSONWriter.getPrettyGeneratorFactory(); generator = gf.createGenerator(sw); } else generator = Json.createGenerator(sw); generator.writeStartObject(); generator.write("domainName", model.getDomainName()); writeModel(model, generator); generator.writeEnd(); generator.flush(); return sw.toString(); }
/** * {@inheritDoc} */ @Override public void encode(Event message, Writer writer) throws EncodeException, IOException { JsonGenerator g = Json.createGenerator(writer); g.writeStartObject() .write("event", message.getEvent()) .write("channel", message.getChannel()); if (!message.getParameters().isEmpty()) { g.writeStartObject("parameters"); message.getParameters().forEach((k, v) -> g.write(k, v)); g.writeEnd(); } g.writeEnd(); g.flush(); }
@Override public void ends() { jsonWriter.writeEnd(); jsonWriter.write(KEY_SIZE,size); if (nbErrors > 0) { jsonWriter.write(KEY_NB_ERRORS, nbErrors); jsonWriter.writeStartArray(KEY_ERRORS); for (String error : errors){ jsonWriter.write(error); } jsonWriter.writeEnd(); } jsonWriter.writeEnd(); jsonWriter.flush(); } }
public void parse(DicomInputStream dis) throws IOException { dis.setIncludeBulkData(includeBulkData); dis.setBulkDataDescriptor(bulkDataDescriptor); dis.setBulkDataDirectory(blkDirectory); dis.setBulkDataFilePrefix(blkFilePrefix); dis.setBulkDataFileSuffix(blkFileSuffix); dis.setConcatenateBulkDataFiles(catBlkFiles); JsonGenerator jsonGen = createGenerator(System.out); JSONWriter jsonWriter = new JSONWriter(jsonGen); dis.setDicomInputHandler(jsonWriter); dis.readDataset(-1, -1); jsonGen.flush(); }
public void parse(DicomInputStream dis) throws IOException { dis.setIncludeBulkData(includeBulkData); dis.setBulkDataDescriptor(bulkDataDescriptor); dis.setBulkDataDirectory(blkDirectory); dis.setBulkDataFilePrefix(blkFilePrefix); dis.setBulkDataFileSuffix(blkFileSuffix); dis.setConcatenateBulkDataFiles(catBlkFiles); JsonGenerator jsonGen = createGenerator(System.out); JSONWriter jsonWriter = new JSONWriter(jsonGen); dis.setDicomInputHandler(jsonWriter); dis.readDataset(-1, -1); jsonGen.flush(); }