@Override public void flush() throws IOException { if (generator != null) { generator.flush(); } }
@Override public void flush() throws IOException { delegate.flush(); }
private void flush() { try { g.flush(); } catch ( IOException e ) { throw new WebApplicationException( e ); } }
@Override public void complete() { try { // todo only if needed g.flush(); } catch ( IOException e ) { throw new WebApplicationException( e ); } } }
@Override public void flush() { try { generator.flush(); } catch (IOException ex) { throw new EsHadoopSerializationException(ex); } }
@Override public void flush() throws IOException { parser.processImplicitActions(); if (out != null) { out.flush(); } }
public String toString() { try { StringWriter writer = new StringWriter(); JsonGenerator gen = Schema.FACTORY.createJsonGenerator(writer); toJson(gen); gen.flush(); return writer.toString(); } catch (IOException e) { throw new AvroRuntimeException(e); } } void toJson(JsonGenerator gen) throws IOException {
private String readBody( JsonParser jp ) throws IOException { JsonNode node = mapper.readTree( jp ); StringWriter out = new StringWriter(); JsonGenerator gen = jsonFactory .createJsonGenerator(out); mapper.writeTree( gen, node ); gen.flush(); gen.close(); return out.toString(); }
/** * Method to serialize given Json Tree, using generator * provided. * * @since 1.1 */ public void writeTree(JsonGenerator jgen, JsonNode rootNode, SerializationConfig cfg) throws IOException, JsonProcessingException { _serializerProvider.serializeValue(cfg, jgen, rootNode, _serializerFactory); if (cfg.isEnabled(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } }
/** * Method to serialize given JSON Tree, using generator * provided. */ @Override public void writeTree(JsonGenerator jgen, JsonNode rootNode) throws IOException, JsonProcessingException { SerializationConfig config = copySerializationConfig(); _serializerProvider.serializeValue(config, jgen, rootNode, _serializerFactory); if (config.isEnabled(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } }
public void startOperation( String from, Integer id ) throws IOException { bytesWritten = 0; g.writeStartObject(); if ( id != null ) { g.writeNumberField( "id", id ); } g.writeStringField( "from", from ); g.writeRaw( ",\"body\":" ); g.flush(); }
/** * This method must be called exactly once, and no method must be called after calling this method. * This method may not fail. */ public void finish() { try { ensureDocumentOpen(); if ( currentState != State.ERRORS_WRITTEN ) { errors( Collections.emptyList() ); } out.writeEndObject(); out.flush(); } catch ( IOException e ) { loggedIOException( e ); } }
@Override public void encode(Trace trace, OutputStream outputStream) throws IOException { final JsonGenerator generator = OBJECT_MAPPER.getJsonFactory().createJsonGenerator(outputStream, JsonEncoding.UTF8); JsonTraceSerializer.serialize(trace, generator); generator.flush(); }
protected void toJsonUtf8(JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("id", getId()); bodyToJsonUtf8(generator); generator.writeEndObject(); generator.flush(); } /**
/** * Method that can be used to serialize any Java value as * JSON output, using provided {@link JsonGenerator}. */ @Override public void writeValue(JsonGenerator jgen, Object value) throws IOException, JsonGenerationException, JsonMappingException { SerializationConfig config = copySerializationConfig(); if (config.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) { _writeCloseableValue(jgen, value, config); } else { _serializerProvider.serializeValue(config, jgen, value, _serializerFactory); if (config.isEnabled(SerializationConfig.Feature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } } }
private JsonNode write( Map<String, Object> row ) throws IOException, JsonParseException { ByteArrayOutputStream out = new ByteArrayOutputStream(); JsonGenerator json = jsonFactory.createJsonGenerator( out ); json.writeStartObject(); try { new GraphExtractionWriter().write( json, row.keySet(), new MapRow( row ), checker ); } finally { json.writeEndObject(); json.flush(); } return JsonHelper.jsonNode( out.toString( UTF_8.name() ) ); }
@Override public Map<String, String> writeRecord(final Record record) throws IOException { // If we are not writing an active record set, then we need to ensure that we write the // schema information. if (!isActiveRecordSet()) { generator.flush(); schemaAccess.writeHeader(recordSchema, getOutputStream()); } writeRecord(record, recordSchema, generator, g -> g.writeStartObject(), g -> g.writeEndObject(), true); return schemaAccess.getAttributes(recordSchema); }
private JsonNode serialize( ByteArrayOutputStream out, JsonGenerator json, ResultDataContentWriter resultDataContentWriter ) throws IOException, JsonParseException { json.writeStartObject(); // RETURN {one:{two:[true, {three: 42}]}} resultDataContentWriter.write( json, asList( "the column" ), new MapRow( map( "the column", map( "one", map( "two", asList( true, map( "three", 42 ) ) ) ) ) ), null ); json.writeEndObject(); json.flush(); json.close(); String jsonAsString = out.toString(); return jsonNode( jsonAsString ).get( "rest" ); } }
private JsonNode serialize( ByteArrayOutputStream out, JsonGenerator json, ResultDataContentWriter resultDataContentWriter ) throws IOException, JsonParseException { json.writeStartObject(); // RETURN {one:{two:[true, {three: 42}]}} resultDataContentWriter.write( json, asList( "the column" ), new MapRow( map( "the column", map( "one", map( "two", asList( true, map( "three", 42 ) ) ) ) ) ), null ); json.writeEndObject(); json.flush(); json.close(); String jsonAsString = out.toString(); return jsonNode( jsonAsString ).get( "row" ); } }
@Override public WriteResult writeRawRecord(final Record record) throws IOException { // If we are not writing an active record set, then we need to ensure that we write the // schema information. if (!isActiveRecordSet()) { generator.flush(); schemaAccess.writeHeader(recordSchema, getOutputStream()); } writeRecord(record, recordSchema, generator, g -> g.writeStartObject(), g -> g.writeEndObject(), false); final Map<String, String> attributes = schemaAccess.getAttributes(recordSchema); return WriteResult.of(incrementRecordCount(), attributes); }