List of usage examples for org.json.simple JSONArray isEmpty
public boolean isEmpty()
From source file:scheduler.ServerThread.java
@SuppressWarnings("unchecked") public void localReceive(PrintWriter out) throws InterruptedException, ParseException { JSONArray responseList = new JSONArray(); JSONParser parser = new JSONParser(); int batchSize = 10; while (msg_cnt > 0) { while (!localRespQ.isEmpty()) { //waiting up to 100ms for an element to become available. String messageBody = localRespQ.poll(100, TimeUnit.MILLISECONDS); JSONObject resp = (JSONObject) parser.parse(messageBody); responseList.add(resp);/*w w w . ja v a 2 s . com*/ msg_cnt--; if (responseList.size() == batchSize) { out.println(responseList.toString()); responseList.clear(); } } if (!responseList.isEmpty()) { out.println(responseList.toString()); responseList.clear(); } } }
From source file:scheduler.ServerThread.java
@SuppressWarnings("unchecked") public void remoteBatchReceive(PrintWriter out) throws ParseException { JSONArray responseList = new JSONArray(); JSONParser parser = new JSONParser(); while (msg_cnt > 0) { while (resQ.getQueueSize() > 0) { //Get up to 10 messages List<Message> messages = resQ.batchReceive(); for (Message message : messages) { // System.out.println(" Message"); // System.out.println(" MessageId: " + message.getMessageId()); // System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); // System.out.println(" MD5OfBody: " + message.getMD5OfBody()); // System.out.println(" Body: " + message.getBody()); //Get task String messageBody = message.getBody(); JSONObject resp = (JSONObject) parser.parse(messageBody); responseList.add(resp);/*from w w w . j a va 2 s .c o m*/ msg_cnt--; // Delete the message String messageRecieptHandle = message.getReceiptHandle(); resQ.deleteMessage(messageRecieptHandle); } if (!responseList.isEmpty()) { out.println(responseList.toString()); responseList.clear(); } } } }
From source file:smops.dao.BusinessManager.java
public static void prepareReport(int offset, int limit) { JSONArray all_json = new JSONArray(); final List<Business> bizs = getBusinesses(offset, limit); for (Business biz : bizs) { if (getValidFormsCount(biz) == 0) { continue; }// w ww.j av a 2s .com // System.out.println(""); // System.out.println("[" + biz.getName() + "] " + biz.getUrl()); JSONObject biz_json = new JSONObject(); biz_json.put("name", biz.getName()); // biz_json.put("url", biz.getUrl()); JSONArray forms_json = new JSONArray(); for (Object f : biz.getForms()) { Form form = (Form) f; if (form.getPurpose().equals("unknown")) { continue; } JSONObject f_json = new JSONObject(); f_json.put("page_url", " " + form.getPageUrl() + " "); f_json.put("purpose", form.getPurpose()); // System.out.println("\t" + form.getPageUrl()); // System.out.print("\t[" + form.getPurpose() + "]: "); String fields_str = ""; for (Object inp : form.getFields()) { Field field = (Field) inp; if (field.getInfoType().equals("unknown")) { continue; } fields_str += field.getInfoType() + " "; } f_json.put("fields", fields_str); forms_json.add(f_json); // System.out.println(fields_str); } if (!forms_json.isEmpty()) { biz_json.put("forms", forms_json); } if (!biz_json.isEmpty()) { all_json.add(biz_json); } } StringWriter out = new StringWriter(); try { all_json.writeJSONString(out); } catch (IOException ex) { Logger.getLogger(BusinessManager.class.getName()).log(Level.SEVERE, null, ex); } String jsonText = out.toString(); System.out.print(jsonText.replaceAll("/", "")); }
From source file:smops.dao.BusinessManager.java
public static void prepareTableReport(List<Business> bizs) { JSONArray all_json = new JSONArray(); for (Business biz : bizs) { // if (getValidFormsCount(biz) == 0) { // continue; // } // System.out.println(""); // System.out.println("[" + biz.getName() + "] " + biz.getUrl()); JSONObject biz_json = new JSONObject(); biz_json.put("name", biz.getName()); // biz_json.put("url", biz.getUrl()); JSONArray forms_json = new JSONArray(); for (Object f : biz.getForms()) { Form form = (Form) f;/*from w ww . ja v a 2 s.co m*/ // if (!form.getPurpose().equals("unknown")) { // continue; // } JSONObject f_json = new JSONObject(); f_json.put("page_url", " " + form.getPageUrl() + " "); f_json.put("purpose", form.getPurpose()); System.out.print(biz.getName() + "\t"); System.out.print(form.getPageUrl() + "\t"); System.out.print(form.getPurpose() + "\t"); // System.out.println("\t" + form.getPageUrl()); // System.out.print("\t[" + form.getPurpose() + "]: "); String fields_str = ""; List<String> fields_infoType = new ArrayList<>(); for (Object inp : form.getFields()) { Field field = (Field) inp; fields_infoType.add(field.getInfoType()); } for (String inftype : Constants.infoType_keywords.keySet()) { if (fields_infoType.contains(inftype)) { System.out.print("1\t"); } else { System.out.print(" \t"); } } for (Object inp : form.getFields()) { Field field = (Field) inp; if (field.getInfoType().equals("unknown")) { continue; } fields_str += field.getInfoType() + " "; } f_json.put("fields", fields_str); forms_json.add(f_json); // System.out.println(fields_str); System.out.println(); } if (!forms_json.isEmpty()) { biz_json.put("forms", forms_json); } if (!biz_json.isEmpty()) { all_json.add(biz_json); } } StringWriter out = new StringWriter(); try { all_json.writeJSONString(out); } catch (IOException ex) { Logger.getLogger(BusinessManager.class.getName()).log(Level.SEVERE, null, ex); } String jsonText = out.toString(); // System.out.print(jsonText.replaceAll("/", "")); }