List of usage examples for org.json.simple.parser ParseException getMessage
public String getMessage()
From source file:com.bigdata.dastor.tools.SSTableImport.java
/** * Converts JSON to an SSTable file. JSON input can either be a file specified * using an optional command line argument, or supplied on standard in. * /* ww w. ja va 2s. co m*/ * @param args command line arguments * @throws IOException on failure to open/read/write files or output streams * @throws ParseException on failure to parse JSON input */ public static void main(String[] args) throws IOException, ParseException { String usage = String.format("Usage: %s -K keyspace -c column_family <json> <sstable>%n", SSTableImport.class.getName()); CommandLineParser parser = new PosixParser(); try { cmd = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException e1) { System.err.println(e1.getMessage()); System.err.println(usage); System.exit(1); } if (cmd.getArgs().length != 2) { System.err.println(usage); System.exit(1); } String json = cmd.getArgs()[0]; String ssTable = cmd.getArgs()[1]; String keyspace = cmd.getOptionValue(KEYSPACE_OPTION); String cfamily = cmd.getOptionValue(COLFAM_OPTION); importJson(json, keyspace, cfamily, ssTable); System.exit(0); }
From source file:kjscompiler.Program.java
/** * @param args//from ww w .j a v a 2 s .com * the command line arguments */ public static void main(String[] args) { ArgScanner as = new ArgScanner(args); if (as.checkValue(settingsArgName)) { settingsPath = as.getValue(settingsArgName); } if (as.checkValue(debugArgName)) { isDebug = true; } try { run(); } catch (ParseException ex) { System.out.println("Parse Exception: " + ex.getMessage()); if (isDebug) { ex.printStackTrace(new PrintStream(System.out)); } System.exit(-1); } catch (IOException ex) { System.out.println("IO Exception: " + ex.getMessage()); if (isDebug) { ex.printStackTrace(new PrintStream(System.out)); } System.exit(-2); } catch (NullPointerException ex) { System.out.println("NullPointer Exception: " + ex.getMessage()); if (isDebug) { ex.printStackTrace(new PrintStream(System.out)); } System.exit(-3); } catch (Exception ex) { System.out.println("Exception: " + ex.getMessage()); if (isDebug) { ex.printStackTrace(new PrintStream(System.out)); } System.exit(-100); } System.exit(1); }
From source file:net.sourceforge.fenixedu.dataTransferObject.externalServices.TeacherPublicationsInformation.java
public static Map<Teacher, List<String>> getTeacherPublicationsInformations(Set<Teacher> teachers) { Map<Teacher, List<String>> teacherPublicationsInformationMap = new HashMap<Teacher, List<String>>(); Client client = ClientBuilder.newClient(); WebTarget resource = client.target(BASE_URL); List<String> teacherIds = new ArrayList<String>(); for (Teacher teacher : teachers) { teacherIds.add(teacher.getTeacherId()); }/*from ww w. j av a2 s .co m*/ resource = resource.path(CURRICULUM_PATH).queryParam("istids", StringUtils.join(teacherIds, ",")); try { String allPublications = resource.request().get(String.class); JSONParser parser = new JSONParser(); for (Object teacherPublications : (JSONArray) parser.parse(allPublications)) { JSONObject teacherPublicationsInfo = (JSONObject) teacherPublications; final String username = (String) teacherPublicationsInfo.get("istID"); final Teacher teacher = Teacher.readByIstId(username); JSONArray preferredPublications = (JSONArray) teacherPublicationsInfo.get("preferred"); List<String> teacherPublicationsList = new ArrayList<String>(); for (Object publication : preferredPublications) { teacherPublicationsList.add(publication.toString()); } teacherPublicationsInformationMap.put(teacher, teacherPublicationsList); } } catch (ParseException e) { logger.error(e.getMessage(), e); } finally { client.close(); } return teacherPublicationsInformationMap; }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.driver.couchdb.CouchDBUtil.java
/** * Add id and revision to the content of a given request * * @param request the given request// w ww. ja v a2 s.co m * @param id the id to add * @param revision the revision to add * @return the modified request */ public static Request addIdAndRevisionToContent(Request request, String id, String revision) { JSONParser parser = new JSONParser(); try { JSONObject jsonObject = (JSONObject) parser.parse((String) request.getContent()); jsonObject.put("_id", id); jsonObject.put("_rev", revision); String jsonString = jsonObject.toJSONString(); log.info("Updated Request content with id and rev: " + jsonString); return new Request.Builder(request.getProtocolType(), request.getRequestType(), request.getUrl(), request.getHost(), request.getPort()).contentType(request.getContentType()).content(jsonString) .build(); } catch (ParseException e) { throw new DatastoreException("Error parsing JSON to add revision: " + e.getMessage()); } }
From source file:fr.itldev.koya.webscript.KoyaWebscript.java
/** * Extracts JSON POST data./* w w w . ja v a 2s . c om*/ * * @param req * @return * @throws java.io.IOException */ public static Map<String, Object> getJsonMap(WebScriptRequest req) throws IOException { JSONParser parser = new JSONParser(); // TODO improve json POST reading try { return (JSONObject) parser.parse(req.getContent().getContent()); } catch (ParseException ex) { LOGGER.error(ex.getMessage(), ex); } return new HashMap<>(); }
From source file:com.ecofactor.qa.automation.util.JsonUtil.java
/** * Parses the object.//from ww w. java2 s . c o m * @param content the content * @return the jSON object */ public static JSONObject parseObject(final String content) { final JSONParser parser = new JSONParser(); try { return (JSONObject) parser.parse(content); } catch (ParseException e) { LOGGER.error(e.getMessage()); } return null; }
From source file:com.ecofactor.qa.automation.util.JsonUtil.java
/** * Parses the array.//from w w w .jav a 2 s .c om * @param content the content * @return the jSON array */ public static JSONArray parseArray(final String content) { final JSONParser parser = new JSONParser(); try { return (JSONArray) parser.parse(content); } catch (ParseException e) { LOGGER.error(e.getMessage()); } return null; }
From source file:h.scratchpads.list.json.JSONReader.java
private static JSONArray readJSON(String jsonFileUrl, LogFile logFile) { String info;/*w w w.j a v a2s. c o m*/ String jsonStr = URLReader.readFromUrl(jsonFileUrl, logFile); JSONArray arrayJSON = null; if (!HkStrings.isNullOrEmptyString(jsonStr)) { JSONParser parser = new JSONParser(); Object obj = null; try { obj = parser.parse(jsonStr); arrayJSON = (JSONArray) obj; } catch (ParseException ex) { info = "Unable to parse JSON file at the URL: \n" + jsonFileUrl + "\n"; info = info + "Exception: " + ex.getMessage(); logFile.write("\n!!!\n" + info + "\n!!!\n"); System.out.println(info); } } else { info = "No data from JSON file at URL: \n" + jsonFileUrl; logFile.write("\n!!!\n" + info + "\n!!!\n"); System.out.println(info); } return arrayJSON; }
From source file:com.apigee.edge.config.utils.ConfigReader.java
/** * API Config/*from w w w.ja v a2 s .c o m*/ * [ {apiProduct1}, {apiProduct2}, {apiProduct3} ] */ public static List getAPIConfig(File configFile) throws ParseException, IOException { Logger logger = LoggerFactory.getLogger(ConfigReader.class); JSONParser parser = new JSONParser(); ArrayList out = null; try { BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile)); JSONArray resourceConfigs = (JSONArray) parser.parse(bufferedReader); if (resourceConfigs == null) return null; out = new ArrayList(); for (Object config : resourceConfigs) { out.add(((JSONObject) config).toJSONString()); } } catch (IOException ie) { logger.info(ie.getMessage()); throw ie; } catch (ParseException pe) { logger.info(pe.getMessage()); throw pe; } return out; }
From source file:com.apigee.edge.config.utils.ConfigReader.java
/** * Example Hierarchy// w ww . ja v a2 s . c o m * envConfig.cache.<env>.caches * * Returns List of * [ {cache1}, {cache2}, {cache3} ] */ public static List getEnvConfig(String env, File configFile) throws ParseException, IOException { Logger logger = LoggerFactory.getLogger(ConfigReader.class); JSONParser parser = new JSONParser(); ArrayList out = null; try { BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile)); JSONArray configs = (JSONArray) parser.parse(bufferedReader); if (configs == null) return null; out = new ArrayList(); for (Object config : configs) { out.add(((JSONObject) config).toJSONString()); } } catch (IOException ie) { logger.info(ie.getMessage()); throw ie; } catch (ParseException pe) { logger.info(pe.getMessage()); throw pe; } return out; }