List of usage examples for java.lang StringBuilder length
int length();
From source file:com.smartqa.utils.WebDriverUtils.java
/** * analysis page performance by w3c web performance API<br/> * inject javascript to get the performance time * /*from w w w. j a v a 2 s .c o m*/ * @param driver - web driver instance * @return map stored performance data */ public static Map<String, Long> analysis(WebDriver driver) { Map<String, Long> dataMap = buildMap(); try { StringBuilder timeData = new StringBuilder() .append(((RemoteWebDriver) driver).executeScript(w3cPerfScript).toString()); timeData.deleteCharAt(0); timeData.deleteCharAt(timeData.length() - 1); Map<String, String> timeMap = CommonUtils.buildMap(timeData.toString().split(",")); dataMap.put(DNS_TIME, getTime(DNS_START, DNS_END, timeMap)); dataMap.put(TCP_TIME, getTime(TCP_START, TCP_END, timeMap)); dataMap.put(SERVER_TIME, getTime(SERVER_START, SERVER_END, timeMap)); dataMap.put(PAGE_TIME, getTime(PAGE_START, PAGE_END, timeMap)); } catch (Exception ex) { LOG.warn("failed to resolve performance data, caused by " + ex.getMessage()); } return dataMap; }
From source file:FileUtils.java
/** * Utility method for concatenation names of collection of files * @param files - array of strings to concatenate * @return concatenated string/*from w ww. j a v a 2 s .c om*/ */ public static String joinFiles(String... files) { final StringBuilder res = new StringBuilder(); for (String file : files) { res.append(file).append(File.separatorChar); } return res.substring(0, res.length() - 1); }
From source file:org.psikeds.resolutionengine.datalayer.vo.ValueObject.java
protected static String composeId(final ValueObject... vos) { final StringBuilder sb = new StringBuilder(); if (vos != null) { for (final ValueObject v : vos) { final String vid = (v == null ? null : v.getId()); if (!StringUtils.isEmpty(vid)) { if (sb.length() > 0) { sb.append(COMPOSE_ID_SEPARATOR); }/*from w w w. java 2 s. c o m*/ sb.append(vid.trim()); } } } return sb.toString(); }
From source file:net.certiv.json.util.Strings.java
public static String csvList(List<String> stringList) { if (stringList == null) return ""; StringBuilder sb = new StringBuilder(); for (String str : stringList) { sb.append(str + ", "); }/*from w ww . j av a2s.c o m*/ int len = sb.length(); sb.delete(len - 2, len); return sb.toString(); }
From source file:com.janrain.backplane2.server.Scope.java
public static String getEncodedScopesAsString(BackplaneMessage.Field field, @NotNull List<String> scopeValues) { StringBuilder sb = new StringBuilder(); for (String value : scopeValues) { if (sb.length() > 0) sb.append(SEPARATOR);//from w ww . j ava 2 s . c o m sb.append(field.getFieldName()).append(DELIMITER).append(value); } return sb.toString(); }
From source file:eionet.cr.util.sesame.SPARQLQueryUtil.java
/** * Builds a comma-separated String of SPARQL aliases the given parameter values. Fills bindings with correct values. Example: * urisToCSV(List{<http://uri1.notexist.com>, <http://uri2.notexist.com>}, "subjectValue")= ?subjectValue1,subjectValue2. * bindings are filled: subjectValue1=http://uri1.notexist.com, subjectValue2=http://uri2.notexist.com * * @param uriList uris to be used as SPARQL parameters * @param variableAliasName prefix for the value alias in the SPARQL query * @param bindings SPARQL bindings/* w w w . j a v a 2 s. c o m*/ * @return comma separated String for Sparql */ public static String urisToCSV(Collection<String> uriList, String variableAliasName, Bindings bindings) { StringBuilder strBuilder = new StringBuilder(); if (uriList != null) { int i = 1; for (String uri : uriList) { String alias = variableAliasName + i; if (strBuilder.length() > 0) { strBuilder.append(","); } // if URI contains spaces - use IRI() function that makes an IRI from URI and seems to work with spaces as well if (isIRI(uri)) { strBuilder.append("?" + alias); } else { strBuilder.append("IRI(?" + alias + ")"); } if (bindings != null) { bindings.setIRI(alias, uri); } i++; } } return strBuilder.toString(); }
From source file:eu.udig.omsbox.utils.OmsBoxUtils.java
private static void toTable(StringBuilder sbToAppendTo, StringBuilder tableContentSb, String tableTitle) { if (tableContentSb.length() > 0) { sbToAppendTo.append("<h3>" + tableTitle + "</h3>").append(NEWLINE); sbToAppendTo.append("<table width=\"100%\" border=\"1\" cellpadding=\"10\">").append(NEWLINE); sbToAppendTo.append(tableContentSb); sbToAppendTo.append("</table>").append(NEWLINE); }/*from w w w .ja v a 2 s . c o m*/ }
From source file:Dump.java
/** * Retorna uma string de tamanho fixo, contendo a representao hexadecimal do valor. * * @param value valor inteiro, de base 10, a ser convertido para base 16. * * @param length comprimento total desejado. * * @return Representao hexadecimal do valor com o comprimento especificado. * A string resultante ser completada com zeros esquerda at que o * comprimento total desejado seja atingido. * Se a representao hexadecimal do valor resultar em um comprimento maior * que o especificado, a string resultante ser formada de asteriscos, * indicando que o comprimento especificado no foi suficiente para o valor. *///from w w w.j av a 2 s.c o m public static String hex(final int value, final int length) { StringBuilder str = new StringBuilder(Integer.toString(value, 16).toUpperCase()); if (str.length() < length) { int falta = (length - str.length()); for (int i = 1; i <= falta; i++) { str.insert(0, "0"); } } else if (str.length() > length) { str = new StringBuilder(); for (int i = 1; i <= length; i++) { str.append("*"); } } return str.toString(); }
From source file:info.bonjean.quinkana.Main.java
private static void run(String[] args) throws QuinkanaException { Properties properties = new Properties(); InputStream inputstream = Main.class.getResourceAsStream("/config.properties"); try {//from ww w . j a v a 2 s. c o m properties.load(inputstream); inputstream.close(); } catch (IOException e) { throw new QuinkanaException("cannot load internal properties", e); } String name = (String) properties.get("name"); String description = (String) properties.get("description"); String url = (String) properties.get("url"); String version = (String) properties.get("version"); String usage = (String) properties.get("help.usage"); String defaultHost = (String) properties.get("default.host"); int defaultPort = Integer.valueOf(properties.getProperty("default.port")); ArgumentParser parser = ArgumentParsers.newArgumentParser(name).description(description) .epilog("For more information, go to " + url).version("${prog} " + version).usage(usage); parser.addArgument("ACTION").type(Action.class).choices(Action.tail, Action.list).dest("action"); parser.addArgument("-H", "--host").setDefault(defaultHost) .help(String.format("logstash host (default: %s)", defaultHost)); parser.addArgument("-P", "--port").type(Integer.class).setDefault(defaultPort) .help(String.format("logstash TCP port (default: %d)", defaultPort)); parser.addArgument("-f", "--fields").nargs("+").help("fields to display"); parser.addArgument("-i", "--include").nargs("+").help("include filter (OR), example host=example.com") .metavar("FILTER").type(Filter.class); parser.addArgument("-x", "--exclude").nargs("+") .help("exclude filter (OR, applied after include), example: severity=debug").metavar("FILTER") .type(Filter.class); parser.addArgument("-s", "--single").action(Arguments.storeTrue()).help("display single result and exit"); parser.addArgument("--version").action(Arguments.version()).help("output version information and exit"); Namespace ns = parser.parseArgsOrFail(args); Action action = ns.get("action"); List<String> fields = ns.getList("fields"); List<Filter> includes = ns.getList("include"); List<Filter> excludes = ns.getList("exclude"); boolean single = ns.getBoolean("single"); String host = ns.getString("host"); int port = ns.getInt("port"); final Socket clientSocket; final InputStream is; try { clientSocket = new Socket(host, port); is = clientSocket.getInputStream(); } catch (IOException e) { throw new QuinkanaException("cannot connect to the server " + host + ":" + port, e); } // add a hook to ensure we clean the resources when leaving Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { is.close(); } catch (IOException e) { e.printStackTrace(); } try { clientSocket.close(); } catch (IOException e) { e.printStackTrace(); } } }); // prepare JSON parser ObjectMapper mapper = new ObjectMapper(); JsonFactory jsonFactory = mapper.getFactory(); JsonParser jp; try { jp = jsonFactory.createParser(is); } catch (IOException e) { throw new QuinkanaException("error during JSON parser creation", e); } JsonToken token; // action=list if (action.equals(Action.list)) { try { // do this in a separate loop to not pollute the main loop while ((token = jp.nextToken()) != null) { if (token != JsonToken.START_OBJECT) continue; // parse object JsonNode node = jp.readValueAsTree(); // print fields Iterator<String> fieldNames = node.fieldNames(); while (fieldNames.hasNext()) System.out.println(fieldNames.next()); System.exit(0); } } catch (IOException e) { throw new QuinkanaException("error during JSON parsing", e); } } // action=tail try { while ((token = jp.nextToken()) != null) { if (token != JsonToken.START_OBJECT) continue; // parse object JsonNode node = jp.readValueAsTree(); // filtering (includes) if (includes != null) { boolean skip = true; for (Filter include : includes) { if (include.match(node)) { skip = false; break; } } if (skip) continue; } // filtering (excludes) if (excludes != null) { boolean skip = false; for (Filter exclude : excludes) { if (exclude.match(node)) { skip = true; break; } } if (skip) continue; } // if no field specified, print raw output (JSON) if (fields == null) { System.out.println(node.toString()); if (single) break; continue; } // formatted output, build and print the string StringBuilder sb = new StringBuilder(128); for (String field : fields) { if (sb.length() > 0) sb.append(" "); if (node.get(field) != null && node.get(field).textValue() != null) sb.append(node.get(field).textValue()); } System.out.println(sb.toString()); if (single) break; } } catch (IOException e) { throw new QuinkanaException("error during JSON parsing", e); } }
From source file:com.rincliu.library.util.RLNetUtil.java
/** * Returns MAC address of the given interface name. * /*from w ww . j a v a 2 s . co m*/ * @param interfaceName eth0, wlan0 or NULL=use first interface * @return mac address or empty string */ public static String getMACAddress(String interfaceName) { try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { if (interfaceName != null) { if (!intf.getName().equalsIgnoreCase(interfaceName)) continue; } byte[] mac = intf.getHardwareAddress(); if (mac == null) return ""; StringBuilder buf = new StringBuilder(); for (int idx = 0; idx < mac.length; idx++) buf.append(String.format("%02X:", mac[idx])); if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1); return buf.toString(); } } catch (Exception ex) { } // for now eat exceptions return ""; // try // { // this is so Linux hack return // loadFileAsString("/sys/class/net/" + interfaceName + // "/address").toUpperCase().trim(); // } // catch (IOException e) // { // e.printStackTrace(); // return null; // } }