List of usage examples for java.util Formatter Formatter
public Formatter()
From source file:com.flexive.war.beans.admin.main.SystemInfoBean.java
/** * Get amount of free memory//from ww w .j av a2 s . c o m * * @return amount of free memory */ public String getFreeMemoryMB() { return new Formatter().format("%.2f MB (of %.2f MB, max. %.2f MB)", (double) Runtime.getRuntime().freeMemory() / 1024. / 1024., (double) Runtime.getRuntime().totalMemory() / 1024. / 1024., (double) Runtime.getRuntime().maxMemory() / 1024. / 1024.).toString(); }
From source file:com.pivotal.gemfire.tools.pulse.internal.service.MemberClientsService.java
public JSONObject execute(final HttpServletRequest request) throws Exception { // get cluster object Cluster cluster = Repository.get().getCluster(); // json object to be sent as response JSONObject responseJSON = new JSONObject(); try {/*from w w w .j av a 2s . com*/ JSONObject requestDataJSON = new JSONObject(request.getParameter("pulseData")); String memberName = requestDataJSON.getJSONObject("MemberClients").getString("memberName"); JSONArray clientListJson = new JSONArray(); Cluster.Member clusterMember = cluster.getMember(StringUtils.makeCompliantName(memberName)); if (clusterMember != null) { responseJSON.put("memberId", clusterMember.getId()); responseJSON.put(this.NAME, clusterMember.getName()); responseJSON.put(this.HOST, clusterMember.getHost()); // member's clients Cluster.Client[] memberClients = clusterMember.getMemberClients(); for (Cluster.Client memberClient : memberClients) { JSONObject regionJSON = new JSONObject(); regionJSON.put("clientId", memberClient.getId()); regionJSON.put(this.NAME, memberClient.getName()); regionJSON.put(this.HOST, memberClient.getHost()); regionJSON.put("queueSize", memberClient.getQueueSize()); regionJSON.put("uptime", TimeUtils.convertTimeSecondsToHMS(memberClient.getUptime())); Formatter fmt = new Formatter(); regionJSON.put("cpuUsage", fmt.format("%.4f", memberClient.getCpuUsage()).toString()); // regionJSON.put("cpuUsage", memberClient.getCpuUsage()); regionJSON.put("threads", memberClient.getThreads()); regionJSON.put("gets", memberClient.getGets()); regionJSON.put("puts", memberClient.getPuts()); clientListJson.put(regionJSON); fmt.close(); } responseJSON.put("memberClients", clientListJson); } // Send json response return responseJSON; } catch (JSONException e) { throw new Exception(e); } }
From source file:edu.cmu.tetrad.cli.simulation.data.AbstractDataSimulationCli.java
protected String printInformation(Simulation simulation) { Formatter fmt = new Formatter(); fmt.format("================================================================================%n"); fmt.format("%s (%s)%n", getSimulationType().getTitle(), AppTool.fmtDateNow()); fmt.format("================================================================================%n"); fmt.format("Description: %s%n", simulation.getDescription()); fmt.format("Delimiter: %s%n", Args.getDelimiterName(delimiter)); fmt.format("Number of Variables: %d%n", numOfVariables); fmt.format("Number of Cases: %d%n", numOfCases); fmt.format("Directory Out: %s%n", dirOut.getFileName().toString()); fmt.format("Output File Prefix: %s%n", outputPrefix); printSimulationParameters(fmt);/*from www. j a va 2 s . co m*/ return fmt.toString().trim(); }
From source file:com.codealot.textstore.FileStore.java
private static String byteToHex(final byte[] hash) { final Formatter formatter = new Formatter(); for (final byte b : hash) { formatter.format("%02X", b); }//from w w w .jav a 2s . c o m final String result = formatter.toString(); formatter.close(); return result; }
From source file:edu.berkeley.compbio.ml.cluster.hierarchical.HierarchicalCentroidCluster.java
/** * {@inheritDoc}/*from w ww . jav a 2 s . c om*/ */ @Override public String toString() { final Formatter f = new Formatter(); f.format("l=%.2f w=%.2f %s", length, weight, value);//%[Cluster %d] n=%d sd=%.2f", id, n, getStdDev()); return f.out().toString(); }
From source file:ome.io.nio.AbstractFileSystemService.java
private String getPath(String prefix, Long id) { String suffix = ""; Long remaining = id;/*from w ww. ja v a2 s . co m*/ Long dirno = 0L; if (id == null) { throw new NullPointerException("Expecting a not-null id."); } while (remaining > 999) { remaining /= 1000; if (remaining > 0) { Formatter formatter = new Formatter(); dirno = remaining % 1000; suffix = formatter.format("Dir-%03d", dirno).out().toString() + File.separator + suffix; } } String path = FilenameUtils.concat(root, prefix + suffix + id); return path; }
From source file:org.apache.camel.component.mongodb.AbstractMongoDbTest.java
protected void pumpDataIntoTestCollection() { // there should be 100 of each String[] scientists = { "Einstein", "Darwin", "Copernicus", "Pasteur", "Curie", "Faraday", "Newton", "Bohr", "Galilei", "Maxwell" }; for (int i = 1; i <= 1000; i++) { int index = i % scientists.length; Formatter f = new Formatter(); String doc = f.format("{\"_id\":\"%d\", \"scientist\":\"%s\", \"fixedField\": \"fixedValue\"}", i, scientists[index]).toString(); testCollection.insert((DBObject) JSON.parse(doc), WriteConcern.SAFE); }/* w w w . java 2 s .com*/ assertEquals("Data pumping of 1000 entries did not complete entirely", 1000L, testCollection.count()); }
From source file:org.apache.abdera.ext.gdata.GoogleLoginAuthScheme.java
protected String getAuth(String id, String pwd, String service) { try {/*from w w w.j a v a2s.c o m*/ AbderaClient abderaClient = new AbderaClient(); Formatter f = new Formatter(); f.format("Email=%s&Passwd=%s&service=%s&source=%s", URLEncoder.encode(id, "utf-8"), URLEncoder.encode(pwd, "utf-8"), (service != null) ? URLEncoder.encode(service, "utf-8") : "", URLEncoder.encode(Version.APP_NAME, "utf-8")); StringRequestEntity stringreq = new StringRequestEntity(f.toString(), "application/x-www-form-urlencoded", "utf-8"); String uri = "https://www.google.com/accounts/ClientLogin"; RequestOptions options = abderaClient.getDefaultRequestOptions(); options.setContentType("application/x-www-form-urlencoded"); ClientResponse response = abderaClient.post(uri, stringreq, options); InputStream in = response.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); int n = -1; while ((n = in.read()) != -1) { out.write(n); } out.flush(); response.release(); String auth = new String(out.toByteArray()); return auth.split("\n")[2].replaceAll("Auth=", "auth="); } catch (Exception e) { } return null; }
From source file:com.codedx.burp.security.InvalidCertificateDialogStrategy.java
public static String toHexString(byte[] bytes, String sep) { Formatter f = new Formatter(); for (int i = 0; i < bytes.length; i++) { f.format("%02x", bytes[i]); if (i < bytes.length - 1) { f.format(sep);/*from w ww. j a v a 2 s . c om*/ } } String result = f.toString(); f.close(); return result; }
From source file:com.flexive.war.beans.admin.main.ScriptConsoleBean.java
/** * Runs the given script code/*from w w w .j av a 2 s . c o m*/ */ public void runScript() { if (StringUtils.isBlank(code)) new FxFacesMsgErr("Script.err.noCodeProvided").addToContext(); else { long start = System.currentTimeMillis(); try { result = runScript(code, "console." + language, web); } catch (Throwable t) { final StringWriter writer = new StringWriter(); t.printStackTrace(new PrintWriter(writer)); final String msg = t.getCause() != null ? t.getCause().getMessage() : t.getMessage(); result = new Formatter().format("Exception caught: %s%n%s", msg, writer.getBuffer()); } finally { executionTime = System.currentTimeMillis() - start; } } }