List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.rincliu.library.util.RLNetUtil.java
/** * Returns MAC address of the given interface name. * /*from ww w . j av a2 s . c o 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; // } }
From source file:com.zxy.commons.lang.utils.StringsUtils.java
/** * ??/* w w w . j a va 2s . c o m*/ * * @param arr * @return */ public static String array2String(String[] arr) { StringBuilder tmp = new StringBuilder(); if (arr != null && arr.length > 0) { for (String a : arr) { tmp.append(DEFAULT_SPLIT).append(a); } tmp.deleteCharAt(0); } return tmp.toString(); }
From source file:com.fhc25.percepcion.osiris.mapviewer.common.data.OsirisBackendCaller.java
private static String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null;//from w w w .j a v a2s.c o m int lineCount = 0; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); lineCount++; } if (lineCount == 1) { sb.deleteCharAt(sb.length() - 1); } is.close(); } catch (IOException e) { } return sb.toString(); }
From source file:com.linkedin.flashback.http.HttpUtilities.java
/** * Converts an ordered map of key / value pairs to a URL parameter string * @param params the map of key / value pairs * @return a string representation of the key / value pairs, delimited by '&' *///from ww w .ja va2 s .co m static public String urlParamsToString(Map<String, String> params, String charset) throws UnsupportedEncodingException { if (params.size() == 0) { return ""; } StringBuilder resultBuilder = new StringBuilder(); for (Map.Entry<String, String> entry : params.entrySet()) { String encodedName = URLEncoder.encode(entry.getKey(), charset); String encodedValue = URLEncoder.encode(entry.getValue(), charset); resultBuilder.append(encodedName).append("=").append(encodedValue).append("&"); } resultBuilder.deleteCharAt(resultBuilder.length() - 1); return resultBuilder.toString(); }
From source file:com.symphony.jirabot.clients.QuandlClient.java
private static String mapToQueryString(HashMap<String, Object> parameters) { if (parameters == null || parameters.size() == 0) { return ""; }// ww w .j av a 2 s. c om StringBuilder queryString = new StringBuilder("&"); for (String key : parameters.keySet()) { queryString.append(urlEncodeUTF8(key)); queryString.append("="); queryString.append(urlEncodeUTF8(parameters.get(key).toString())); queryString.append("&"); } if (queryString.charAt(queryString.length() - 1) == '&') { queryString = queryString.deleteCharAt(queryString.length() - 1); } return queryString.toString(); }
From source file:com.ibm.sbt.security.encryption.HMACEncryptionUtility.java
public static String generateParameterString(Map<String, String> paramsMap) { StringBuilder parameterString = new StringBuilder(); for (Map.Entry<String, String> entry : paramsMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); parameterString.append(key).append("=").append(percentEncode(value)).append("&"); }// w ww.java 2 s .c om // Now remove the last & and return the string. return parameterString.deleteCharAt(parameterString.length() - 1).toString(); }
From source file:com.servoy.j2db.server.ngclient.startup.resourceprovider.ComponentResourcesExporter.java
/** * Used in war export to create a services.properties file, which is needed to load services specs in the war. * @return the locations of services folders relative to the war dir. */// w w w . java2s .co m public static String getServicesDirectoryNames() { StringBuilder locations = new StringBuilder(); Enumeration<String> paths = Activator.getContext().getBundle().getEntryPaths("/war/"); while (paths.hasMoreElements()) { String name = paths.nextElement().replace("war/", ""); if (name.endsWith("services/")) locations.append("/" + name + ";"); } if (locations.length() > 0) locations.deleteCharAt(locations.length() - 1); return locations.toString(); }
From source file:Main.java
public static String buildString(Map<String, String> params) { if (params == null || params.size() == 0) return null; StringBuilder sb = new StringBuilder(); Set<Entry<String, String>> setEntry = params.entrySet(); for (Entry<String, String> entry : setEntry) { sb.append(entry.getKey());/* ww w.j a va 2s . c o m*/ sb.append("="); try { sb.append(getUrlEncode(entry.getValue(), "utf-8") + "&"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:de.blizzy.documentr.util.Util.java
/** * Converts a text so that it can be used as a URL component. For example, the text * "<code>My Funny Valentine</code>" will be converted to * "<code>my-funny-valentine</code>". This method is useful to convert * page titles to page path components./*w w w . j a va 2 s . c o m*/ */ public static String simplifyForUrl(String text) { PagePathValidator validator = new PagePathValidator(); StringBuilder buf = new StringBuilder(); int len = text.length(); for (int i = 0; i < len; i++) { char c = text.charAt(i); if (StringUtils.contains(CHARS_TO_DASH, c)) { buf.append("-"); //$NON-NLS-1$ } else { buf.append(c); if (!validator.isValid(buf.toString(), null)) { buf.deleteCharAt(buf.length() - 1); } } } String name = buf.toString().replaceAll("--", "-") //$NON-NLS-1$ //$NON-NLS-2$ .replaceAll("^-", StringUtils.EMPTY) //$NON-NLS-1$ .replaceAll("-$", StringUtils.EMPTY) //$NON-NLS-1$ .toLowerCase(); return name; }
From source file:io.cloudslang.content.couchbase.utils.InputsUtil.java
public static String getPayloadString(Map<String, String> payloadMap, String separator, String suffix, boolean deleteLastChar) { if (payloadMap.isEmpty()) { return EMPTY; }// w ww .j a va 2 s .co m StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : payloadMap.entrySet()) { sb.append(entry.getKey()).append(separator).append(entry.getValue()).append(suffix); } return deleteLastChar ? sb.deleteCharAt(sb.length() - 1).toString() : sb.toString(); }