List of usage examples for org.json.simple.parser ParseException printStackTrace
public void printStackTrace()
From source file:org.apache.hadoop.mapreduce.approx.lib.input.SampleRecordReader.java
public boolean nextKeyValue1() throws IOException, InterruptedException { while (nextKeyValueOrg()) { String currentValue = ((Text) this.getCurrentValue()).toString(); JSONObject jsonCurrentValue = null; try {//from w w w. ja v a 2s .c o m jsonCurrentValue = (JSONObject) parser.parse(currentValue); } catch (ParseException e) { e.printStackTrace(); } //LOG.info(currentValue); String[] keys = this.split.getKeys(idx - 1).split(Pattern.quote("*+*")); for (String key : keys) { //*************************************************************************fields separator********************** String[] fields = key.split(Pattern.quote("+*+")); boolean containCurrentKey = true; for (int i = 0; i < fields.length; i++) { //LOG.info("filter:" + field); String[] jsonwhere = whereKeys[fields.length - 1 - i].split(Pattern.quote("="))[0] .split(Pattern.quote(".")); JSONObject jsonkey = jsonCurrentValue; String jsonvalue = ""; boolean flag = true; for (int j = 0; j < jsonwhere.length; j++) { flag = true; if (jsonkey.containsKey(jsonwhere[j])) { if (fields[i].equals("true")) { continue; } if (jsonkey.get(jsonwhere[j]).getClass().getName().equals("java.lang.String")) { jsonvalue = (String) jsonkey.get(jsonwhere[j]); flag = false; } else { jsonkey = (JSONObject) jsonkey.get(jsonwhere[j]); } } else { containCurrentKey = false; break; } } if (!containCurrentKey) { break; } if (fields[i].equals("true")) { continue; } if (flag) { jsonvalue = jsonkey.toString(); } if (!jsonvalue.toLowerCase().contains(fields[i].toLowerCase())) { containCurrentKey = false; break; } } if (containCurrentKey) { return true; } } } return false; }
From source file:org.apache.metron.dataloads.cif.HBaseTableLoad.java
private void parse(String[] args) { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("d", true, "description"); options.addOption("t", true, "description"); options.addOption("f", false, "description"); CommandLine cmd = null;//ww w .j ava 2s.c o m try { cmd = parser.parse(options, args); if (cmd.hasOption("d")) { this.dirName = cmd.getOptionValue("d"); LOG.info("Directory Name:" + cmd.getOptionValue("d")); } else { LOG.info("Missing Directory Name"); printUsage(); System.exit(-1); } if (cmd.hasOption("t")) { this.hbaseTable = cmd.getOptionValue("t"); LOG.info("HBase Table Name:" + cmd.getOptionValue("t")); } else { LOG.info("Missing Table Name"); printUsage(); System.exit(-1); } if (cmd.hasOption("f")) { this.usefileList = true; files = LoadFileList(cmd.getOptionValue("f")); LOG.info("FileList:" + cmd.getOptionValue("f")); } } catch (org.apache.commons.cli.ParseException e) { LOG.error("Failed to parse comand line properties", e); e.printStackTrace(); System.exit(-1); } }
From source file:org.aprilis.jrest.compile.Test.java
/** * @param args//from ww w . j a v a2 s . c o m */ public static void main(String[] args) { // TODO Auto-generated method stub String json = "{\"JDBC\":{" + "\"Query\":\"SELECT * FROM Darwin.User\", " + "\"Type\":\"GET\", " + "\"Roles\":[\"\", \"\", \"3\"]" + "}}\n"; String sampleQuery = "SELECT ? FROM ? USERS ? Me too ? howdy stoya"; String splitArray[] = sampleQuery.split("\\?"); // long x = Long.parseLong(System.getenv("JREST_REFRESH_INTERVAL")); // System.out.println(x); InputStream stream = Test.class.getResourceAsStream("/jdbc.json"); System.out.println(stream != null); stream = Store.class.getClassLoader().getResourceAsStream("jdbc.json"); System.out.println(stream != null); System.out.println(sampleQuery); for (short i = 0; i < splitArray.length; i++) System.out.println(splitArray[i]); System.out.println(json); JSONParser parser = new JSONParser(); try { // JSONObject table = (JSONObject) parser.parse(json); @SuppressWarnings("unchecked") HashMap<String, HashMap<String, Object>> jTable = (JSONObject) parser.parse(json); ; // HashMap<String, Object> jEntries; for (Map.Entry<String, HashMap<String, Object>> entry : jTable.entrySet()) { System.out.println(entry.getKey()); System.out.println(entry.getValue().getClass()); // jEntries = (HashMap<String, Object>) entry.getValue(); for (Map.Entry<String, Object> values : entry.getValue().entrySet()) { System.out.println("'" + values.getKey() + "'"); // System.out.println(values.getValue().getClass().getName()); if (values.getValue() instanceof JSONArray) { JSONArray ja = (JSONArray) values.getValue(); for (short i = 0; i < ja.size(); i++) System.out.println("\t" + ja.get(i).toString()); } else { System.out.println(values.getValue().toString()); } } } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.arkanos.aos.api.data.Goal.java
/** * Creates a goal object based on a JSON file. * //from w ww .j a va 2 s . c om * @param from * defines the source of the JSON. * @param user_name * defines the user to own the goal. * @return the created goal instance. */ static public Goal parseGoal(Reader from, String user_name) { JSONParser jp = new JSONParser(); try { //TODO: Find a better JSON library. JSONObject jo = (JSONObject) jp.parse(from); String id = "" + jo.get(Goal.FIELD_ID); String title = "" + jo.get(Goal.FIELD_TITLE); String time_planned = "" + jo.get(Goal.FIELD_TIME_PLANNED); String description = "" + jo.get(Goal.FIELD_DESCRIPTION); Goal newone = new Goal(Integer.parseInt(id), title, (int) (Float.parseFloat(time_planned) * 60), description, user_name); newone.setCompletion(Float.parseFloat("" + jo.get(Task.EXTRA_COMPLETION))); newone.setTotalTimeSpent((int) (Float.parseFloat("" + jo.get(Goal.EXTRA_TOTAL_TIME_SPENT)) * 60)); return newone; } catch (ParseException e1) { Log.error("Goal", "Problems while parsing a goal from a JSON."); e1.printStackTrace(); } catch (IOException e) { Log.error("Goal", "Problems while reading data to be parsed."); e.printStackTrace(); } return null; }
From source file:org.arkanos.aos.api.data.Task.java
/** * Creates a task object based on a JSON file. * // w w w.j av a2 s. c o m * @param from * defines the source of the JSON. * @return the created task instance. */ static public Task parseTask(Reader from) { JSONParser jp = new JSONParser(); try { //TODO: Find a better JSON library. JSONObject jo = (JSONObject) jp.parse(from); String id = "" + jo.get(Task.FIELD_ID); String goal_id = "" + jo.get(Task.FIELD_GOAL_ID); String name = "" + jo.get(Task.FIELD_NAME); String initial = "" + jo.get(Task.FIELD_INITIAL); String target = "" + jo.get(Task.FIELD_TARGET); Task newone = new Task(Integer.parseInt(id), Integer.parseInt(goal_id), name, Float.parseFloat(initial), Float.parseFloat(target)); newone.setGoalTitle("" + jo.get(Task.EXTRA_GOAL_TITLE)); newone.setCompletion(Float.parseFloat("" + jo.get(Task.EXTRA_COMPLETION))); newone.setCurrent(Float.parseFloat("" + jo.get(Task.EXTRA_CURRENT))); newone.setTotalTimeSpent((int) (Float.parseFloat("" + jo.get(Task.EXTRA_TOTAL_TIME_SPENT)) * 60)); return newone; } catch (ParseException e1) { Log.error("Task", "Problems while parsing a Task from a JSON."); e1.printStackTrace(); } catch (IOException e) { Log.error("Task", "Problems while reading data to be parsed."); e.printStackTrace(); } return null; }
From source file:org.basket3.filesystem.bo.GsonSerializer.java
public Object deserialize(String s) throws SerializationException { JSONParser parser = new JSONParser(); try {/*from w w w.j a v a 2s . c om*/ return parser.parse(s); } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:org.daxplore.producer.daxplorelib.raw.RawMeta.java
@SuppressWarnings("rawtypes") protected static List<Pair<String, Double>> JSONtoCategories(String jsonstring) { List<Pair<String, Double>> list = new LinkedList<>(); JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory() { @Override// w ww . j av a 2 s . c o m public List creatArrayContainer() { return new LinkedList(); } @Override public Map createObjectContainer() { return new LinkedHashMap(); } }; Map json; try { json = (Map) parser.parse(jsonstring, containerFactory); } catch (ParseException e) { e.printStackTrace(); return null; } Iterator iter = json.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); list.add(new Pair<>((String) entry.getValue(), Double.parseDouble((String) entry.getKey()))); } return list; }
From source file:org.eclairjs.nashorn.Utils.java
public static Object[] convertBindArgs(Object bindArgs, SparkContext sc) { if (bindArgs != null) { boolean inJar = true; Object[] bindArr = (Object[]) ScriptUtils.convert(bindArgs, Object[].class); for (int i = 0; i < bindArr.length; i++) { if (ModuleUtils.isModule(bindArr[i])) { ScriptObjectMirror som = ModuleUtils.getRequiredFile(bindArr[i]); // som=(ScriptObjectMirror)ScriptObjectMirror.wrapAsJSONCompatible(som,null); // String j = JSONValue.toJSONString(som); String j = toJSON(som); JSONObject json = null;/* w ww . j a va 2 s . c o m*/ try { json = (JSONObject) new JSONParser().parse(j); } catch (ParseException e) { e.printStackTrace(); } Object v = json.get("core"); if (v instanceof Boolean && ((Boolean) v).booleanValue()) { } else inJar = false; bindArr[i] = json; } else { bindArr[i] = Utils.jsToJava(bindArr[i]); } } if (!inJar && !sc.isLocal()) { ModuleUtils.addCustomFiles(sc); } return bindArr; } return null; }
From source file:org.eclipse.californium.proxy.HttpTranslator.java
public static void getHttpOptions(HttpRequest httpRequest, Response coapResponse, HttpResponse httpResponse) { // TODO Auto-generated method stub String response = coapResponse.getPayloadString(); JSONParser parser = new JSONParser(); try {//from w w w . j a va 2 s. c o m JSONObject obj = (JSONObject) parser.parse(response); JSONArray allow = (JSONArray) obj.get("Allow"); JSONArray accept_post = (JSONArray) obj.get("Accept-Post"); JSONArray accept_patch = (JSONArray) obj.get("Accept-Patch"); if (allow != null) { String allow_string = allow.toJSONString(); allow_string = allow_string.replace("\"", ""); allow_string = allow_string.replace("[", ""); allow_string = allow_string.replace("]", ""); Header allow_header = new BasicHeader("Allow", allow_string); httpResponse.addHeader(allow_header); } if (accept_post != null) { String accept_post_string = accept_post.toJSONString(); accept_post_string = accept_post_string.replace("\"", ""); accept_post_string = accept_post_string.replace("\\", ""); accept_post_string = accept_post_string.replace("[", ""); accept_post_string = accept_post_string.replace("]", ""); Header accept_post_header = new BasicHeader("Accept-Post", accept_post_string); httpResponse.addHeader(accept_post_header); } if (accept_patch != null) { String accept_patch_string = accept_patch.toJSONString(); accept_patch_string = accept_patch_string.replace("\"", ""); accept_patch_string = accept_patch_string.replace("\\", ""); accept_patch_string = accept_patch_string.replace("[", ""); accept_patch_string = accept_patch_string.replace("]", ""); Header accept_patch_header = new BasicHeader("Accept-Patch", accept_patch_string); httpResponse.addHeader(accept_patch_header); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.ethereum.jsontestsuite.JSONReader.java
public static String getTestBlobForTreeSha(String shacommit, String testcase) { String result = getFromUrl("https://api.github.com/repos/ethereum/tests/git/trees/" + shacommit); JSONParser parser = new JSONParser(); JSONObject testSuiteObj = null;//from w ww. j a v a2s . c om List<String> fileNames = new ArrayList<String>(); try { testSuiteObj = (JSONObject) parser.parse(result); JSONArray tree = (JSONArray) testSuiteObj.get("tree"); for (Object oEntry : tree) { JSONObject entry = (JSONObject) oEntry; String testName = (String) entry.get("path"); if (testName.equals(testcase)) { String blobresult = getFromUrl((String) entry.get("url")); testSuiteObj = (JSONObject) parser.parse(blobresult); String blob = (String) testSuiteObj.get("content"); byte[] valueDecoded = Base64.decodeBase64(blob.getBytes()); //System.out.println("Decoded value is " + new String(valueDecoded)); return new String(valueDecoded); } } } catch (ParseException e) { e.printStackTrace(); } return ""; }