List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:minecrunch_launcher.Client.java
public void run() { // Reading modpack profile XML file and getting profile parameters if (os.contains("Windows")) { minecraftDir = home + "\\AppData\\Roaming\\.minecraft\\"; tempDir = home + "\\AppData\\temp\\"; clientInstall = tempDir + "client_install\\"; modinstallDir = home + "\\AppData\\Roaming\\.minecraft\\minecrunch\\"; }//from w ww.ja v a 2 s .c o m if (os.contains("Linux")) { minecraftDir = home + "/.minecraft/"; tempDir = home + "/temp/"; clientInstall = tempDir + "client_install/"; modinstallDir = home + "/.minecraft/minecrunch/"; } if (os.contains("Mac")) { minecraftDir = home + "/Library/Application Support/minecraft/"; tempDir = home + "/temp/"; clientInstall = tempDir + "client_install/"; modinstallDir = home + "/Library/Application Support/minecraft/minecrunch/"; } try { Modprofile(); } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException ex) { Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); } // Install selected modpack wd.setVisible(true); System.out.println("Modpack picked: " + name); System.out.println("Gamename is: " + gamename); File dir = new File(tempDir); if (!dir.exists()) { if (dir.mkdir()) { String console = "Temporary directory created."; System.out.println(console); } else { String console = "Temporary directory already exists."; System.out.println(console); } } URL url = null; try { url = new URL("http://www.minecrunch.net/download/" + name + "/client_install.zip"); } catch (MalformedURLException ex) { System.out.println(ex); } File file = new File(tempDir + "client_install.zip"); try { FileUtils.copyURLToFile(url, file); } catch (IOException ex) { System.out.println(ex); } try { ZipFile zipFile = new ZipFile(tempDir + "client_install.zip"); zipFile.extractAll(tempDir); } catch (ZipException e) { } file.delete(); File newlib = new File(clientInstall + "libraries"); File oldlib = new File(minecraftDir + "libraries"); try { FileUtils.copyDirectory(newlib, oldlib); System.out.println("Copied libraries directory."); FileUtils.deleteDirectory(newlib); System.out.println("Deleted libraries directory."); } catch (IOException ex) { System.out.println(ex); } File newver = new File(clientInstall + "versions"); File oldver = new File(minecraftDir + "versions"); try { FileUtils.copyDirectory(newver, oldver); System.out.println("Copied version directory."); FileUtils.deleteDirectory(newver); System.out.println("Deleted version directory."); } catch (IOException ex) { System.out.println(ex); } File newmods = new File(clientInstall); File oldmods = new File(modinstallDir + name + "\\"); try { FileUtils.copyDirectory(newmods, oldmods); System.out.println("Copied all other directories."); } catch (IOException ex) { System.out.println(ex); } try { // delete temporary directory FileUtils.deleteDirectory(dir); } catch (IOException ex) { System.out.println(ex); } // Setup profile String profile = gamename; String gamedir = modinstallDir + name; String filePath = minecraftDir + "launcher_profiles.json"; JSONParser parser = new JSONParser(); Object obj = null; try { obj = parser.parse(new FileReader(filePath)); } catch (IOException | ParseException ex) { } JSONObject jsonObject = (JSONObject) obj; JSONObject profiles = (JSONObject) jsonObject.get("profiles"); String selectedProfile = profile; String clientToken = (String) jsonObject.get("clientToken"); JSONObject authenticationDatabase = (JSONObject) jsonObject.get("authenticationDatabase"); JSONObject params = new JSONObject(); params.put("name", profile); params.put("gameDir", gamedir); params.put("lastVersionId", version); params.put("javaArgs", java); profiles.put(profile, params); JSONObject update = new JSONObject(); update.put("profiles", profiles); update.put("selectedProfile", selectedProfile); update.put("clientToken", clientToken); update.put("authenticationDatabase", authenticationDatabase); try (FileWriter newfile = new FileWriter(filePath)) { newfile.write(update.toJSONString()); newfile.flush(); } catch (IOException ex) { System.out.println(ex); } wd.setVisible(false); }
From source file:com.nubits.nubot.tasks.SubmitLiquidityinfoTask.java
private void initFiles() { if (SessionManager.sessionInterrupted()) return; //external interruption this.outputFile_orders = Global.sessionLogFolder + "/" + Settings.ORDERS_FILENAME + ".csv"; this.jsonFile_orders = Global.sessionLogFolder + "/" + Settings.ORDERS_FILENAME + ".json"; this.jsonFile_balances = Global.sessionLogFolder + "/" + Settings.BALANCES_FILEAME + ".json"; //create json file if it doesn't already exist LOG.debug("init files"); File jsonF1 = new File(this.jsonFile_orders); if (!jsonF1.exists()) { try {//from w w w . jav a 2s .co m jsonF1.createNewFile(); LOG.debug("created " + jsonF1); } catch (Exception e) { LOG.error("error creating file " + jsonF1 + " " + e); } JSONObject history = new JSONObject(); JSONArray orders = new JSONArray(); history.put("orders", orders); FilesystemUtils.writeToFile(history.toJSONString(), this.jsonFile_orders, true); } if (SessionManager.sessionInterrupted()) return; //external interruption //create json file if it doesn't already exist File jsonF2 = new File(this.jsonFile_balances); if (!jsonF2.exists()) { try { jsonF2.createNewFile(); LOG.debug("created " + jsonF2); } catch (Exception e) { LOG.error("error creating file " + jsonF1 + " " + e); } JSONObject history = new JSONObject(); JSONArray balances = new JSONArray(); history.put("balances", balances); FilesystemUtils.writeToFile(history.toJSONString(), this.jsonFile_balances, true); } if (SessionManager.sessionInterrupted()) return; //external interruption File of = new File(this.outputFile_orders); if (!of.exists()) { try { of.createNewFile(); LOG.debug("created " + of); } catch (Exception e) { LOG.error("error creating file " + of + " " + e); } } FilesystemUtils.writeToFile("timestamp,activeOrders, sells,buys, digest\n", this.outputFile_orders, false); }
From source file:hoot.services.controllers.ogr.TranslatorResource.java
/** * <NAME>Translation Service Node Server status</NAME> * <DESCRIPTION>/* w w w. jav a 2 s . com*/ * Gets current status of translation server. * </DESCRIPTION> * <PARAMETERS> * </PARAMETERS> * <OUTPUT> * JSON containing state and port it is running * </OUTPUT> * <EXAMPLE> * <URL>http://localhost:8080/hoot-services/ogr/translationserver/status</URL> * <REQUEST_TYPE>GET</REQUEST_TYPE> * <INPUT> * </INPUT> * <OUTPUT>{"isRunning":"true","port":"8094"}</OUTPUT> * </EXAMPLE> * @return */ @GET @Path("/translationserver/status") @Produces(MediaType.TEXT_PLAIN) public Response isTranslationServiceRunning() { boolean isRunning = false; try { isRunning = getStatus(transProc); } catch (Exception ex) { ResourceErrorHandler.handleError("Error starting translation service request: " + ex.toString(), Status.INTERNAL_SERVER_ERROR, log); } JSONObject res = new JSONObject(); res.put("isRunning", isRunning); res.put("port", currentPort); return Response.ok(res.toJSONString(), MediaType.APPLICATION_JSON).build(); }
From source file:com.conwet.silbops.connectors.comet.SubCometConnectionTest.java
@Test @SuppressWarnings("unchecked") public void shouldSendMessage() throws IOException, EndPointException { HttpServletResponse respose = mock(HttpServletResponse.class); when(resource.getResponse()).thenReturn(respose); when(respose.getWriter()).thenReturn(writer); final JSONObject payload = new JSONObject(); payload.put("key", "value"); Message message = new Message() { @Override// ww w . ja v a 2 s .c o m public JSONObject getPayloadAsJSON() { return payload; } }; instance.sendMessage(message); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(writer).println(captor.capture()); verify(writer).flush(); assertThat(captor.getValue()).contains("SilboPS.recvMessage").contains(endpointID) .contains(payload.toJSONString().replaceAll("\"", "\\\\\"")); }
From source file:br.bireme.prvtrm.PreviousTermServlet.java
/** * Processes requests for both HTTP/*from www. j ava2 s .c om*/ * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json; charset=UTF-8"); final PrintWriter out = response.getWriter(); try { final String init = request.getParameter("init"); if (init == null) { throw new ServletException("missing 'init' parameter"); } int maxSize = previous.getMaxSize(); String maxTerms = request.getParameter("maxTerms"); if (maxTerms != null) { maxSize = Integer.parseInt(maxTerms); } List<String> fields = previous.getFields(); String fldsParam = request.getParameter("fields"); if (fldsParam != null) { fields = Arrays.asList(fldsParam.split("[,;\\-]")); } final List<String> terms; String direction = request.getParameter("direction"); if ((direction == null) || (direction.compareToIgnoreCase("next") == 0)) { terms = previous.getNextTerms(init, fields, maxSize); direction = "next"; } else { terms = previous.getPreviousTerms(init, fields, maxSize); direction = "previous"; } final JSONObject jobj = new JSONObject(); final JSONArray jlistTerms = new JSONArray(); final JSONArray jlistFields = new JSONArray(); jlistTerms.addAll(terms); jlistFields.addAll(fields); jobj.put("init", init); jobj.put("direction", direction); jobj.put("maxTerms", maxSize); jobj.put("fields", jlistFields); jobj.put("terms", jlistTerms); out.println(jobj.toJSONString()); } finally { out.close(); } }
From source file:de.metalcon.imageServer.protocol.CreateRequestTest.java
@SuppressWarnings("unchecked") @Before//from w w w. j a v a2s. c om public void setUp() throws IOException { DISK_FILE_REPOSITORY.delete(); DISK_FILE_REPOSITORY.mkdirs(); // JPEG image item final File imageItemJpeg = new File(TEST_FILE_DIRECTORY, "jpeg.jpeg"); VALID_IMAGE_ITEM_JPEG = createImageItem("image/jpeg", imageItemJpeg); assertEquals(imageItemJpeg.length(), VALID_IMAGE_ITEM_JPEG.getSize()); // meta data final JSONObject metaDataCreate = new JSONObject(); metaDataCreate.put("title", "My Great Picture"); metaDataCreate.put("camera", "Testy BFC9000"); metaDataCreate.put("resolution", "yes"); metaDataCreate.put("license", "General More AllYouCanSee License"); metaDataCreate.put("date", "1991-11-11"); metaDataCreate.put("description", "Pixels in a frame!"); VALID_CREATE_META_DATA = metaDataCreate.toJSONString(); }
From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java
@SuppressWarnings("unchecked") protected String getVectorJSON(Vector vec) { JSONObject data = new JSONObject(); // x, y, z/*ww w.j a v a 2 s .c o m*/ data.put("x", String.valueOf(vec.getX())); data.put("y", String.valueOf(vec.getY())); data.put("z", String.valueOf(vec.getZ())); return data.toJSONString(); }
From source file:com.dams.controller.client.ClientController.java
@RequestMapping(value = "/client/login", method = RequestMethod.POST) public @ResponseBody String processLogin(@RequestBody Patient patient, HttpServletRequest request) { JSONObject obj = new JSONObject(); Patient dbPatient = patientService.findByUsername(patient.getUsername()); // System.out.println(dbPatient.getPassword()); if (dbPatient != null) { if (dbPatient.getPassword().equals(patient.getPassword())) { httpsession.setAttribute("patientId", dbPatient.getPatientId()); obj.put("login", 1); } else {//from w w w .jav a2s .c om obj.put("login", 0); } } else { obj.put("login", 0); } return obj.toJSONString(); }
From source file:info.pancancer.arch3.persistence.PostgreSQL.java
public String createJob(Job j) { JSONObject jsonIni = new JSONObject(j.getIni()); Map<Object, Map<String, Object>> map = this.runInsertStatement( "INSERT INTO job (status, job_uuid, workflow, workflow_version, job_hash, ini) VALUES (?,?,?,?,?,?)", new KeyedHandler<>("job_uuid"), j.getState().toString(), j.getUuid(), j.getWorkflow(), j.getWorkflowVersion(), j.getJobHash(), jsonIni.toJSONString()); return (String) map.entrySet().iterator().next().getKey(); }
From source file:com.fujitsu.dc.test.jersey.cell.UpdateTest.java
/** * ?./*from w ww.jav a2s . c o m*/ * @param headers * @param requestBody * @param query * @return Cell?? */ private static DcResponse createCellQuery(final HashMap<String, String> headers, final JSONObject requestBody, final String query) { DcResponse ret = null; DcRestAdapter rest = new DcRestAdapter(); String data = requestBody.toJSONString(); // ?URL? StringBuilder url = new StringBuilder(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME)); if (query != null) { url.append("?" + query); } try { // ret = rest.post(url.toString(), data, headers); } catch (Exception e) { fail(e.getMessage()); } return ret; }