public void saveMetrics(JsonArray o) { HttpURLConnection con = null; try { URL obj = new URL(config.getProperty("r2cloud.hostname") + "/api/v1/metrics"); con = (HttpURLConnection) obj.openConnection(); con.setConnectTimeout(config.getInteger("r2cloud.connectionTimeout")); con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", "r2cloud/0.1 info@r2cloud.ru"); con.setRequestProperty("Authorization", config.getProperty("r2cloud.apiKey")); con.setRequestProperty("Content-Type", "application/json"); con.setDoOutput(true); Writer w = new OutputStreamWriter(con.getOutputStream(), StandardCharsets.UTF_8); o.writeTo(w); w.close(); int responseCode = con.getResponseCode(); if (responseCode != 200) { LOG.error("unable to save meta. response code: " + responseCode + ". See logs for details"); Util.toLog(LOG, con.getErrorStream()); return; } } catch (Exception e) { LOG.error("unable to save metrics", e); } finally { if (con != null) { con.disconnect(); } } }
/** * Adds a new ignored sender ID. This makes sense only if the * current contact is a group. The ID may be an anonymous sender UUID or a * normal from address. * * @param senderID to add */ public void addGroupIgnoredSenderID(String senderID) throws IOException { this.preloadCachedIgnoredGroupSenderIDs(); File ignoredIDsFile = new File(rootDir, IGNORED_GROUP_IDS); Util.renameFileForMultiVersionBackup(rootDir, IGNORED_GROUP_IDS); this.cachedIgnoredGroupSenderIDs.add(senderID); JsonArray ar = new JsonArray(); for (String id : this.cachedIgnoredGroupSenderIDs) { ar.add(id); } OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(ignoredIDsFile)); OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8"); ar.writeTo(osw, WriterConfig.PRETTY_PRINT); osw.flush(); } finally { if (os != null) { os.close(); } } }
ar.writeTo(osw, WriterConfig.PRETTY_PRINT); osw.flush(); } finally
arrayJson.writeTo(response.getWriter());
if (root.isArray()) { try { unflattenArray(root.asArray()).writeTo(sw, getWriterConfig()); } catch (IOException e) {} return sw.toString();
if (root.isArray()) { try { unflattenArray(root.asArray()).writeTo(sw, getWriterConfig()); } catch (IOException e) {} return sw.toString();