List of usage examples for java.io IOException toString
public String toString()
From source file:com.tomtom.speedtools.json.Json.java
/** * Convert an object to a JSON String representation. The returned string may NOT be readable as pure JSON. If you * want to use real JSON, use toJson instead. This method should be used for human readable debugging and logging * purposes only./* www. ja v a 2 s .co m*/ * * @param obj Object to convert. * @return JSON string representation. */ @Nonnull public static String toStringJson(@Nullable final Object obj) { if (obj == null) { return "null"; } String result; try { result = STRING_MAPPER.writeValueAsString(obj); } catch (final JsonMappingException ignored) { // Just ignore. (These occur, for example, as a result of the EqualsVerifier.) result = "error"; } catch (final IOException e) { LOG.error("toStringJson: Cannot map {} --> JSON, {}", obj.getClass().getCanonicalName(), e.toString()); result = "error"; } return result; }
From source file:com.groupme.sdk.util.HttpUtils.java
public static String openUrl(HttpClient client, String url, int method, String body, Bundle params, Bundle headers) throws HttpResponseException { String response = null;/*from w w w . j a v a 2 s . co m*/ InputStream in = openStream(client, url, method, body, params, headers); try { if (in == null) { return null; } response = read(in); Log.d(Constants.LOG_TAG, "Response: " + response); } catch (IOException e) { Log.e(Constants.LOG_TAG, "Error reading response: " + e.toString()); } return response; }
From source file:com.squarespace.template.GeneralUtils.java
/** * Loads a resource from the Java package relative to {@code cls}, raising a * CodeException if it fails./*from w w w .jav a2 s . c om*/ */ public static String loadResource(Class<?> cls, String path) throws CodeException { try (InputStream stream = cls.getResourceAsStream(path)) { if (stream == null) { throw new CodeExecuteException(resourceLoadError(path, "not found")); } return IOUtils.toString(stream, "UTF-8"); } catch (IOException e) { throw new CodeExecuteException(resourceLoadError(path, e.toString())); } }
From source file:org.jetbrains.webdemo.examples.ExamplesLoader.java
private static ExampleFile loadExampleFile(String path, String projectUrl, JsonNode fileManifest) throws IOException { try {/*from ww w . java2 s. c om*/ String fileName = fileManifest.get("filename").textValue(); boolean modifiable = fileManifest.get("modifiable").asBoolean(); boolean hidden = fileManifest.has("hidden") ? fileManifest.get("hidden").asBoolean() : false; String confType = fileManifest.has("confType") ? fileManifest.get("confType").asText() : null; File file = new File(path); String fileContent = new String(Files.readAllBytes(file.toPath())).replaceAll("\r\n", "\n"); String filePublicId = (projectUrl + "/" + fileName).replaceAll(" ", "%20"); ProjectFile.Type fileType = null; if (!fileManifest.has("type")) { fileType = ProjectFile.Type.KOTLIN_FILE; } else if (fileManifest.get("type").asText().equals("kotlin-test")) { fileType = ProjectFile.Type.KOTLIN_TEST_FILE; } else if (fileManifest.get("type").asText().equals("solution")) { fileType = ProjectFile.Type.SOLUTION_FILE; } else if (fileManifest.get("type").asText().equals("java")) { fileType = ProjectFile.Type.JAVA_FILE; } return new ExampleFile(fileName, fileContent, filePublicId, fileType, confType, modifiable, hidden); } catch (IOException e) { System.err.println("Can't load file: " + e.toString()); return null; } }
From source file:it.cnr.isti.thematrix.mapping.utils.TempFileManager.java
/** * get a File pointing to a fresh new temporary file in the iad directory * @return the new temporary file/*from w w w . jav a 2 s .c o m*/ */ public static File newTempFile() { File tempFile; File dir = new File(Dynamic.getResultsPath()); String suffix = Enums.getFileExtension(Dynamic.bufferCompression); try { tempFile = java.io.File.createTempFile("test", suffix, dir); } catch (IOException e) { throw new Error( "TempFileManager - Can't open temp file " + dir.toString() + " exception " + e.toString()); } filenameList.add(tempFile.getAbsolutePath()); return tempFile; }
From source file:com.sunway.cbm.util.web.ServletUtils.java
/** * ?xml?//from ww w. ja v a 2s . c om * * @param response * @param object */ public static void responseXml(HttpServletResponse response, String xml) { try { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(xml); response.getWriter().flush(); response.getWriter().close(); } catch (IOException e) { logger.debug(e.toString()); } }
From source file:com.sunway.cbm.util.ServletUtils.java
/** * ?xml?/*from ww w .j a va2 s . c o m*/ * * @param response * @param object */ public static void responseXml(HttpServletResponse response, String xml) { try { // response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); logger.debug(xml); // response.getWriter().write(xml); // response.getWriter().flush(); // response.getWriter().close(); PrintWriter out = response.getWriter(); out.print(xml); out.close(); } catch (IOException e) { logger.debug(e.toString()); } }
From source file:Hib.ControllerInsertJSON.java
static void doThat() throws MalformedURLException, JSONException { URL Url = new URL("http://api.wunderground.com/api/4228dd85f026caea/conditions/q/Colorado/COS.json"); // URL Url = new URL("http://api.wunderground.com/api/4228dd85f026caea/conditions/q/Mexico/Cancun.json"); //This next URL is still being played with. Some of the formatting is hard to figure out, but Wunderground //writes a perfectly formatted JSON file that is easy to read with Java. // URL Url = new URL("https://api.darksky.net/forecast/08959bb1e2c7eae0f3d1fafb5d538032/38.886,-104.7201"); try {//from ww w .ja va2 s .c o m HttpURLConnection urlCon = (HttpURLConnection) Url.openConnection(); // This part will read the data returned thru HTTP and load it into memory // I have this code left over from my CIT260 project. InputStream stream = urlCon.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); StringBuilder result = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { result.append(line); } // The next lines read certain parts of the JSON data and print it out on the screen //Creates the JSONObject object and loads the JSON file from the URLConnection //Into a StringWriter object. I am printing this out in raw format just so I can see it doing something JSONObject json = new JSONObject(result.toString()); JSONObject coloradoInfo = (JSONObject) json.get("current_observation"); StringWriter out = new StringWriter(); json.write(out); String jsonTxt = json.toString(); System.out.print(jsonTxt); // List<String> list = new ArrayList<>(); // JSONArray array = json.getJSONArray(jsonTxt); // System.out.print(jsonTxt); DB_jason_json person = new DB_jason_json(); person.setJson_id(coloradoInfo.getString("temperature_string")); person.setLax_json(coloradoInfo.getJSONObject("display_location").getString("city")); person.setStrict_json(coloradoInfo.getJSONObject("display_location").getString("state_name")); person.setUnique_json(coloradoInfo.getString("wind_string")); Model.addPerson(person); // session.flush(); //session.close(); // System.out.println(person); System.out.println("JSON ADDED!!!!!"); } catch (IOException e) { System.out.println("***ERROR*******************ERROR********************. " + "\nURL: " + Url.toString() + "\nERROR: " + e.toString()); // for (int i =0;i<array.length();i++){ //list.add(array.getJSONObject(i).getString("current_observation")); //} } }
From source file:org.jetbrains.webdemo.examples.ExamplesLoader.java
private static ExamplesFolder loadFolder(String path, String url, List<ObjectNode> parentCommonFiles, ExamplesFolder parentFolder) {/* www . j av a2s .c o m*/ File manifestFile = new File(path + File.separator + "manifest.json"); try (BufferedInputStream reader = new BufferedInputStream(new FileInputStream(manifestFile))) { ObjectNode manifest = (ObjectNode) JsonUtils.getObjectMapper().readTree(reader); String name = new File(path).getName(); List<ObjectNode> commonFiles = new ArrayList<>(); commonFiles.addAll(parentCommonFiles); boolean taskFolder = manifest.has("taskFolder") ? manifest.get("taskFolder").asBoolean() : false; List<LevelInfo> levels = null; if (manifest.has("levels")) { levels = new ArrayList<>(); for (JsonNode level : manifest.get("levels")) { levels.add(new LevelInfo(level.get("projectsNeeded").asInt(), level.get("color").asText())); } } if (parentFolder != null && parentFolder.isTaskFolder()) taskFolder = true; ExamplesFolder folder = new ExamplesFolder(name, url, taskFolder, levels); if (manifest.has("files")) { for (JsonNode node : manifest.get("files")) { ObjectNode fileManifest = (ObjectNode) node; fileManifest.put("path", path + File.separator + fileManifest.get("filename").asText()); commonFiles.add(fileManifest); } } if (manifest.has("folders")) { for (JsonNode node : manifest.get("folders")) { String folderName = node.textValue(); folder.addChildFolder(loadFolder(path + File.separator + folderName, url + folderName + "/", commonFiles, folder)); } } if (manifest.has("examples")) { for (JsonNode node : manifest.get("examples")) { String projectName = node.textValue(); String projectPath = path + File.separator + projectName; folder.addExample(loadExample(projectPath, url, ApplicationSettings.LOAD_TEST_VERSION_OF_EXAMPLES, commonFiles)); } } return folder; } catch (IOException e) { System.err.println("Can't load folder: " + e.toString()); return null; } }
From source file:axiom.util.Logging.java
/** * Rotate log files on all registered logs */// ww w. j av a2s . c o m static void rotateLogs() { int nloggers = loggers.size(); ArrayList files = new ArrayList(nloggers); for (int i = nloggers - 1; i >= 0; i--) { FileLogger log = (FileLogger) loggers.get(i); try { File file = log.rotateLogFile(); if (file != null) { files.add(file); } } catch (IOException io) { System.err.println("Error rotating log " + log.getName() + ": " + io.toString()); } } if (!files.isEmpty()) { new FileLogger.GZipper(files).start(); } }