List of usage examples for org.json.simple JSONValue writeJSONString
public static void writeJSONString(Object value, Writer out) throws IOException
From source file:com.yahoo.labs.samoa.topology.impl.StormTopologySubmitter.java
public static void main(String[] args) throws IOException { Properties props = StormSamoaUtils.getProperties(); String uploadedJarLocation = props.getProperty(StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY); if (uploadedJarLocation == null) { logger.error("Invalid properties file. It must have key {}", StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY); return;//from w ww . ja v a 2s. co m } List<String> tmpArgs = new ArrayList<String>(Arrays.asList(args)); int numWorkers = StormSamoaUtils.numWorkers(tmpArgs); args = tmpArgs.toArray(new String[0]); StormTopology stormTopo = StormSamoaUtils.argsToTopology(args); Config conf = new Config(); conf.putAll(Utils.readStormConfig()); conf.putAll(Utils.readCommandLineOpts()); conf.setDebug(false); conf.setNumWorkers(numWorkers); String profilerOption = props.getProperty(StormTopologySubmitter.YJP_OPTIONS_KEY); if (profilerOption != null) { String topoWorkerChildOpts = (String) conf.get(Config.TOPOLOGY_WORKER_CHILDOPTS); StringBuilder optionBuilder = new StringBuilder(); if (topoWorkerChildOpts != null) { optionBuilder.append(topoWorkerChildOpts); optionBuilder.append(' '); } optionBuilder.append(profilerOption); conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, optionBuilder.toString()); } Map<String, Object> myConfigMap = new HashMap<String, Object>(conf); StringWriter out = new StringWriter(); try { JSONValue.writeJSONString(myConfigMap, out); } catch (IOException e) { System.out.println("Error in writing JSONString"); e.printStackTrace(); return; } Config config = new Config(); config.putAll(Utils.readStormConfig()); String nimbusHost = (String) config.get(Config.NIMBUS_HOST); NimbusClient nc = new NimbusClient(nimbusHost); String topologyName = stormTopo.getTopologyName(); try { System.out.println("Submitting topology with name: " + topologyName); nc.getClient().submitTopology(topologyName, uploadedJarLocation, out.toString(), stormTopo.getStormBuilder().createTopology()); System.out.println(topologyName + " is successfully submitted"); } catch (AlreadyAliveException aae) { System.out.println("Fail to submit " + topologyName + "\nError message: " + aae.get_msg()); } catch (InvalidTopologyException ite) { System.out.println("Invalid topology for " + topologyName); ite.printStackTrace(); } catch (TException te) { System.out.println("Texception for " + topologyName); te.printStackTrace(); } }
From source file:com.olabini.jescov.generators.JsonGenerator.java
public void generate(CoverageData data) throws IOException { Map genData = convert(data); JSONValue.writeJSONString(genData, writer); }
From source file:com.boundlessgeo.geoserver.json.JSONWrapper.java
/** * Encodes a wrapper as JSON.//w ww . j a v a 2 s . com * * @param obj The wrapper. * @param out Target writer. * */ public static void write(Object value, Writer out) throws IOException { value = wrapOrSelf(value); if (value == null) { out.write("null"); out.flush(); } else if (value instanceof JSONWrapper) { ((JSONWrapper<?>) value).write(out); } else { JSONValue.writeJSONString(value, out); } }
From source file:com.google.android.gcm.demo.server.RegisterServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String regId = getParameter(req, PARAMETER_REG_ID); /* BEGIN MINE */ String conType = getParameter(req, PARAMETER_CON_TYPE, ""); if (conType.equals(PUSH)) { Datastore.toPush(getParameter(req, PARAMETER_OLD_ID), regId); PrintWriter out = resp.getWriter(); JSONValue.writeJSONString(Datastore.getList(regId), out); out.close();//from w w w .java 2s . c o m return; } /* END MINE */ Datastore.register(regId); setSuccess(resp); }
From source file:configuration.GroupAccessBundle.java
/** * {@inheritDoc}//from w ww .ja va 2 s . co m */ @Override public String toString() { Writer writer = new JSONPrettyPrintWriter(); try { JSONValue.writeJSONString(this.toMap(), writer); } catch (IOException e) { e.printStackTrace(); } return writer.toString(); }
From source file:com.tr8n.core.Utils.java
/** * Builds json from an object//from w w w . ja v a2 s . co m * * @param object * @return */ public static String buildJSON(Object object) { if (object == null) return null; StringWriter out = new StringWriter(); try { JSONValue.writeJSONString(object, out); } catch (IOException ex) { Tr8n.getLogger().logException(ex); return null; } return out.toString(); }
From source file:com.nhn.android.archetype.base.object.BaseObj.java
public String toJson() { try {// w w w. ja va 2 s .c o m StringWriter out = new StringWriter(); JSONValue.writeJSONString(getDataMap(), out); return out.toString(); } catch (Exception e) { logger.e(e); } return null; }
From source file:configuration.ClientConfiguration.java
/** * {@inheritDoc}//from w w w. jav a 2 s. c o m */ @Override public String toString() { Writer writer = new JSONPrettyPrintWriter(); try { JSONValue.writeJSONString(toMap(), writer); } catch (IOException e) { e.printStackTrace(); } return writer.toString(); }
From source file:net.bashtech.geobot.Channel.java
public void saveConfig(Boolean shouldSendUpdate) { try {/*from w w w . jav a 2 s. co m*/ FileWriter file = new FileWriter(channel + ".json"); StringWriter out = new StringWriter(); JSONValue.writeJSONString(config, out); String jsonText = out.toString(); file.write(jsonText); // file.write(config.toJSONString()); file.flush(); file.close(); if (shouldSendUpdate) { BotManager.getInstance().postCoebotConfig(config.toJSONString(), twitchname); } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.apache.samoa.topology.impl.StormTopologySubmitter.java
public static void main(String[] args) throws IOException { Properties props = StormSamoaUtils.getProperties(); String uploadedJarLocation = props.getProperty(StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY); if (uploadedJarLocation == null) { logger.error("Invalid properties file. It must have key {}", StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY); return;//from w w w . ja v a 2 s .c o m } List<String> tmpArgs = new ArrayList<String>(Arrays.asList(args)); int numWorkers = StormSamoaUtils.numWorkers(tmpArgs); args = tmpArgs.toArray(new String[0]); StormTopology stormTopo = StormSamoaUtils.argsToTopology(args); Config conf = new Config(); conf.putAll(Utils.readStormConfig()); conf.putAll(Utils.readCommandLineOpts()); conf.setDebug(false); conf.setNumWorkers(numWorkers); String profilerOption = props.getProperty(StormTopologySubmitter.YJP_OPTIONS_KEY); if (profilerOption != null) { String topoWorkerChildOpts = (String) conf.get(Config.TOPOLOGY_WORKER_CHILDOPTS); StringBuilder optionBuilder = new StringBuilder(); if (topoWorkerChildOpts != null) { optionBuilder.append(topoWorkerChildOpts); optionBuilder.append(' '); } optionBuilder.append(profilerOption); conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, optionBuilder.toString()); } Map<String, Object> myConfigMap = new HashMap<String, Object>(conf); StringWriter out = new StringWriter(); try { JSONValue.writeJSONString(myConfigMap, out); } catch (IOException e) { System.out.println("Error in writing JSONString"); e.printStackTrace(); return; } Config config = new Config(); config.putAll(Utils.readStormConfig()); NimbusClient nc = NimbusClient.getConfiguredClient(config); String topologyName = stormTopo.getTopologyName(); try { System.out.println("Submitting topology with name: " + topologyName); nc.getClient().submitTopology(topologyName, uploadedJarLocation, out.toString(), stormTopo.getStormBuilder().createTopology()); System.out.println(topologyName + " is successfully submitted"); } catch (AlreadyAliveException aae) { System.out.println("Fail to submit " + topologyName + "\nError message: " + aae.get_msg()); } catch (InvalidTopologyException ite) { System.out.println("Invalid topology for " + topologyName); ite.printStackTrace(); } catch (TException te) { System.out.println("Texception for " + topologyName); te.printStackTrace(); } }