public void close() throws IOException { if (g != null) { g.close(); } }
@Override public void close() throws IOException { generator.close(); } }
@Override public void close() throws IOException { delegate.close(); }
public void close() throws IOException { g.writeEndArray(); g.close(); }
public void close() throws IOException { if (g != null) { g.writeEndArray(); g.close(); } } }
@Override public void close() throws IOException { jsonGenerator.writeEndObject(); jsonGenerator.close(); }
@Override public void close() { try { generator.close(); } catch (IOException ex) { throw new EsHadoopSerializationException(ex); } }
@Override public void close() throws IOException { if (generator != null) { generator.close(); } super.close(); }
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(); }
public void writeError( int status, String message ) throws IOException { if ( bytesWritten == 0 || bytesWritten == IS_ERROR ) { g.writeRaw( "null" ); } g.writeNumberField( "status", status ); if ( message != null && !message.trim().equals( Response.Status.fromStatusCode( status ).getReasonPhrase() ) ) { g.writeStringField( "message", message ); } else { if ( errorStream != null ) { g.writeStringField( "message", errorStream.toString( StandardCharsets.UTF_8.name() ) ); } } g.close(); } }
@Override public void run() { try { ObjectName q = null; if (query != null) { q = new ObjectName(query); } MBeanServerConnection jmx = conn.getMServer(); JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jg = jsonFactory.createJsonGenerator(System.out); jg.useDefaultPrettyPrinter(); jg.writeStartObject(); listBeans(q, jg, jmx); jg.writeEndObject(); jg.close(); System.out.println(); System.out.flush(); } catch (Exception e) { host.fail(e.toString()); } }
protected final void _configAndWriteValue(JsonGenerator jgen, Object value, Class<?> viewClass) throws IOException, JsonGenerationException, JsonMappingException { SerializationConfig cfg = copySerializationConfig().withView(viewClass); if (cfg.isEnabled(SerializationConfig.Feature.INDENT_OUTPUT)) { jgen.useDefaultPrettyPrinter(); } // [JACKSON-282]: consider Closeable if (cfg.isEnabled(SerializationConfig.Feature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) { _configAndWriteCloseable(jgen, value, cfg); return; } boolean closed = false; try { _serializerProvider.serializeValue(cfg, jgen, value, _serializerFactory); closed = true; jgen.close(); } finally { if (!closed) { try { jgen.close(); } catch (IOException ioe) { } } } }
public static String indentJSON(final String jsonIn) throws JSONParseException{ JsonFactory fac = new JsonFactory(); try{ JsonParser parser = fac.createJsonParser(new StringReader(jsonIn)); JsonNode node = null; try{ node = jsonObjMapper.readTree(parser); } catch(JsonParseException ex){ throw new JSONParseException(ex.getMessage()); } StringWriter out = new StringWriter(); // Create pretty printer: JsonGenerator gen = fac.createJsonGenerator(out); DefaultPrettyPrinter pp = new DefaultPrettyPrinter(); pp.indentArraysWith(new DefaultPrettyPrinter.Lf2SpacesIndenter()); gen.setPrettyPrinter(pp); // Now write: jsonObjMapper.writeTree(gen, node); gen.flush(); gen.close(); return out.toString(); } catch(IOException ex){ LOG.log(Level.SEVERE, null, ex); } return jsonIn; }
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 void showResourcePlans(DataOutputStream out, List<WMResourcePlan> resourcePlans) throws HiveException { JsonGenerator generator = null; try { generator = new ObjectMapper().getJsonFactory().createJsonGenerator(out); generator.writeStartArray(); for (WMResourcePlan plan : resourcePlans) { generator.writeStartObject(); generator.writeStringField("name", plan.getName()); generator.writeStringField("status", plan.getStatus().name()); if (plan.isSetQueryParallelism()) { generator.writeNumberField("queryParallelism", plan.getQueryParallelism()); } if (plan.isSetDefaultPoolPath()) { generator.writeStringField("defaultPoolPath", plan.getDefaultPoolPath()); } generator.writeEndObject(); } generator.writeEndArray(); generator.close(); } catch (IOException e) { throw new HiveException(e); } finally { if (generator != null) { IOUtils.closeQuietly(generator); } } }
public static void createDbExportDump( FileSystem fs, Path metadataPath, Database dbObj, ReplicationSpec replicationSpec) throws IOException, SemanticException { // WARNING NOTE : at this point, createDbExportDump lives only in a world where ReplicationSpec is in replication scope // If we later make this work for non-repl cases, analysis of this logic might become necessary. Also, this is using // Replv2 semantics, i.e. with listFiles laziness (no copy at export time) OutputStream out = fs.create(metadataPath); JsonGenerator jgen = (new JsonFactory()).createJsonGenerator(out); jgen.writeStartObject(); jgen.writeStringField("version",METADATA_FORMAT_VERSION); dbObj.putToParameters(ReplicationSpec.KEY.CURR_STATE_ID.toString(), replicationSpec.getCurrentReplicationState()); if (METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION != null) { jgen.writeStringField("fcversion",METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION); } TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); try { jgen.writeStringField("db", serializer.toString(dbObj, "UTF-8")); } catch (TException e) { throw new SemanticException( ErrorMsg.ERROR_SERIALIZE_METASTORE .getMsg(), e); } jgen.writeEndObject(); jgen.close(); // JsonGenerator owns the OutputStream, so it closes it when we call close. }