List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.DPFaragir.DPFUtils.java
public static String getMACAddress(String interfaceName) { try {/*from ww w . j a v a 2s . c o m*/ 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 ex) { return null; }*/ }
From source file:com.appassit.http.ApiRequestFactory.java
/** * GETurl/*from www. java 2 s.com*/ * * @param url * @param params * @return */ private static String getGetRequestUrl(String url, ArrayList<BasicNameValuePair> params) { if (params == null || params.size() == 0) { return url; } StringBuilder builder = new StringBuilder(); builder.append(url).append("?"); for (BasicNameValuePair entry : params) { Object obj = entry.getValue(); if (obj == null) continue; builder.append(entry.getName()).append("=").append(entry.getValue()).append("&"); } builder.deleteCharAt(builder.length() - 1); return builder.toString(); }
From source file:com.modcrafting.ultrabans.util.Formatting.java
public static String combineSplit(int startIndex, String[] string, String seperator) { StringBuilder builder = new StringBuilder(); if (string.length >= 1) { for (int i = startIndex; i < string.length; i++) { builder.append(string[i]);//from www .ja v a 2 s . c om builder.append(seperator); } if (builder.length() > seperator.length()) { builder.deleteCharAt(builder.length() - seperator.length()); // remove return builder.toString(); } } return Ultrabans.DEFAULT_REASON; }
From source file:com.weibo.api.motan.protocol.restful.support.RestfulUtil.java
public static void encodeAttachments(MultivaluedMap<String, Object> headers, Map<String, String> attachments) { if (attachments == null || attachments.isEmpty()) return;//from w w w. j a va2s . co m StringBuilder value = new StringBuilder(); for (Map.Entry<String, String> entry : attachments.entrySet()) { value.append(StringTools.urlEncode(entry.getKey())).append("=") .append(StringTools.urlEncode(entry.getValue())).append(";"); } if (value.length() > 1) value.deleteCharAt(value.length() - 1); headers.add(ATTACHMENT_HEADER, value.toString()); }
From source file:de.fhg.fokus.odp.portal.managedatasets.utils.HashMapUtils.java
/** * Map to meta data.// w w w .j av a2 s . c om * * @param map * the map * @return the meta data bean * @throws ParseException * the parse exception */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static MetaDataBean mapToMetaData(Map map) throws ParseException { log.debug("HashMap to convert to MetaDataBean: " + map.toString()); MetaDataBean metaData = new MetaDataBean(); metaData.setTitle((String) map.get("title")); metaData.setName((String) map.get("name")); metaData.setAuthor((String) map.get("author")); metaData.setAuthor_email((String) map.get("author_email")); metaData.setMaintainer((String) map.get("maintainer")); metaData.setMaintainer_email((String) map.get("maintainer_email")); metaData.setUrl((String) map.get("url")); metaData.setNotes((String) map.get("notes")); metaData.setLicense_id((String) map.get("license_id")); metaData.setCkanId((String) map.get("id")); metaData.setMetadata_created(DateUtils.stringToDateMetaData((String) map.get("metadata_created"))); metaData.setMetadata_modified(DateUtils.stringToDateMetaData((String) map.get("metadata_modified"))); Map<String, String> extrasMap = new HashMap<String, String>(); extrasMap = (Map) map.get("extras"); metaData.setDate_released(DateUtils.stringToDateTemporalCoverage(extrasMap.get("date_released"))); metaData.setDate_updated(DateUtils.stringToDateTemporalCoverage(extrasMap.get("date_updated"))); metaData.setTemporal_coverage_from(extrasMap.get("temporal_coverage_from")); metaData.setTemporal_coverage_to(extrasMap.get("temporal_coverage_to")); metaData.setTemporal_granularity(extrasMap.get("temporal_granularity")); metaData.setGeographical_coverage(extrasMap.get("geographical_coverage")); metaData.setGeographical_granularity(extrasMap.get("geographical_granularity")); metaData.setOthers(extrasMap.get("others")); metaData.setGroups((List<String>) map.get("groups")); StringBuilder tagsBuilder = new StringBuilder(); for (String tag : (List<String>) map.get("tags")) { tag.trim(); tagsBuilder.append(tag).append(","); } if (tagsBuilder.length() > 0) { tagsBuilder = tagsBuilder.deleteCharAt(tagsBuilder.length() - 1); } metaData.setTags(tagsBuilder.toString()); metaData.setVersion((String) map.get("version")); List<Map<String, String>> resorcesList; resorcesList = (List) map.get("resources"); for (Map<String, String> resMap : resorcesList) { Resource resource = new Resource(); resource.setFormat(resMap.get("format").toUpperCase()); resource.setDescription(resMap.get("description")); resource.setUrl(resMap.get("url")); resource.setLanguage(resMap.get("language")); metaData.getResources().add(resource); } return metaData; }
From source file:de.fhg.fokus.odp.portal.managedatasets.utils.HashMapUtils.java
/** * Meta data to map.//from w ww. j a v a 2s . co m * * @param metaData * the meta data * @return the hash map */ public static HashMap<String, String> metaDataToMap(MetaDataBean metaData) { HashMap<String, String> metaDataMap = new HashMap<String, String>(); HashMap<String, String> extrasMap = new HashMap<String, String>(); List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>(); extrasMap.put("temporal_coverage_from", metaData.getTemporal_coverage_from()); extrasMap.put("temporal_coverage_to", metaData.getTemporal_coverage_to()); extrasMap.put("temporal_granularity", metaData.getTemporal_granularity()); extrasMap.put("geographical_coverage", metaData.getGeographical_coverage()); extrasMap.put("geographical_granularity", metaData.getGeographical_granularity()); extrasMap.put("date_released", DateUtils.dateToStringTemporalCoverage(metaData.getDate_released())); extrasMap.put("others", metaData.getOthers()); for (Resource resource : metaData.getResources()) { Map<String, String> resourceMap = new HashMap<String, String>(); if (!resource.getUrl().isEmpty() && !resource.getFormat().isEmpty()) { resourceMap.put("url", resource.getUrl()); resourceMap.put("format", resource.getFormat().toUpperCase()); resourceMap.put("description", resource.getDescription()); resourceMap.put("language", resource.getLanguage()); resourcesList.add(resourceMap); } } metaDataMap.put("extras", JSONValue.toJSONString(extrasMap)); metaDataMap.put("resources", JSONValue.toJSONString(resourcesList)); if (metaData.getTags().isEmpty()) { metaDataMap.put("tags", "[]"); } else { StringBuilder tagsBuilder = new StringBuilder(); for (String tag : metaData.getTags().split(",")) { tagsBuilder.append("\"" + tag.trim() + "\","); } // remove trailing comma tagsBuilder = tagsBuilder.deleteCharAt(tagsBuilder.length() - 1); metaDataMap.put("tags", "[" + tagsBuilder.toString().trim() + "]"); } metaDataMap.put("groups", JSONValue.toJSONString(metaData.getGroups())); metaDataMap.put("title", "\"" + metaData.getTitle() + "\""); metaDataMap.put("name", "\"" + metaData.getName() + "\""); metaDataMap.put("author", "\"" + metaData.getAuthor() + "\""); metaDataMap.put("author_email", "\"" + metaData.getAuthor_email() + "\""); metaDataMap.put("url", "\"" + metaData.getUrl() + "\""); metaDataMap.put("notes", "\"" + metaData.getNotes() + "\""); metaDataMap.put("license_id", "\"" + metaData.getLicense_id() + "\""); metaDataMap.put("version", "\"" + metaData.getVersion() + "\""); metaDataMap.put("maintainer", "\"" + metaData.getMaintainer() + "\""); metaDataMap.put("maintainer_email", "\"" + metaData.getMaintainer_email() + "\""); metaDataMap.put("metadata_created", "\"" + DateUtils.dateToStringMetaDate(metaData.getMetadata_created()) + "\""); metaDataMap.put("metadata_modified", "\"" + metaData.getMetadata_modified() + "\""); log.info("JSON String for create metadata: " + metaDataMap.toString()); return metaDataMap; }
From source file:ext.sns.util.AuthUtil.java
/** * ?state?state????/* w w w. j ava 2s . c o m*/ * * @param params ? * @return ?state? */ public static String encodeState(Map<String, String> params) { String state = null; try { StringBuilder stateBuilder = new StringBuilder(); for (Map.Entry<String, String> e : params.entrySet()) { stateBuilder.append(URLEncoder.encode(e.getKey(), "utf-8")).append('&'); stateBuilder.append(URLEncoder.encode(e.getValue(), "utf-8")).append('&'); } if (stateBuilder.length() > 0) { stateBuilder.deleteCharAt(stateBuilder.length() - 1); } state = URLEncoder.encode(stateBuilder.toString(), "utf-8").replace('%', '_'); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return state; }
From source file:Main.java
public static HttpEntity getEntity(String uri, ArrayList<BasicNameValuePair> params, int method) throws ClientProtocolException, IOException { mClient = new DefaultHttpClient(); HttpUriRequest request = null;/*from w w w .j av a2s . com*/ switch (method) { case METHOD_GET: StringBuilder sb = new StringBuilder(uri); if (params != null && !params.isEmpty()) { sb.append("?"); for (BasicNameValuePair param : params) { sb.append(param.getName()).append("=").append(URLEncoder.encode(param.getValue(), "UTF_8")) .append("&"); } sb.deleteCharAt(sb.length() - 1); } request = new HttpGet(sb.toString()); break; case METHOD_POST: HttpPost post = new HttpPost(uri); if (params != null && !params.isEmpty()) { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF_8"); post.setEntity(entity); } request = post; break; } mClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000); mClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000); HttpResponse response = mClient.execute(request); System.err.println(response.getStatusLine().toString()); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response.getEntity(); } return null; }
From source file:com.htmlhifive.tools.codeassist.core.proposal.build.CodeBuilderUtils.java
/** * FunctionBean????.<br>/* www . j a va2 s. c o m*/ * ex.<br> * <code> * function(arg1,arg2){return new Return();} * </code> * * @param sb ?. * @param method ???. */ static void addFunctionCode(StringBuilder sb, FunctionBean method) { sb.append("function("); VariableBean[] args = method.getArgments(); boolean existArgs = false; for (VariableBean arg : args) { existArgs = true; sb.append(arg.getName()); sb.append(","); } // if (existArgs) { sb.deleteCharAt(sb.length() - 1); } sb.append("){"); if (StringUtils.isNotEmpty(method.getReturnType()) && !(method.getReturnType().equals("void"))) { sb.append("return new "); sb.append(method.getReturnType()); sb.append("();"); } sb.append("}"); }
From source file:gumga.framework.presentation.api.CSVGeneratorAPI.java
public static String classToCsvTitle(Class clazz) { StringBuilder sb = new StringBuilder(); for (Field f : getAllAtributes(clazz)) { sb.append(f.getName());//from w w w. ja v a2 s. c om sb.append(CSV_SEPARATOR); } sb.deleteCharAt(sb.length() - 1); sb.append(CSV_LINE_DELIMITER); return sb.toString(); }