List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String toString()
From source file:StringUtils.java
/** * Given an array of bytes it will convert the bytes to a hex string * representation of the bytes/* w w w . ja va 2 s . co m*/ * @param bytes * @return hex string representation of the byte array */ public static String byteToHexString(byte bytes[]) { StringBuffer retString = new StringBuffer(); for (int i = 0; i < bytes.length; ++i) { retString.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1)); } return retString.toString(); }
From source file:Main.java
/** * Split X-path string in to string steps, ignoring / characters inside [] * /* ww w. ja v a2 s. c o m*/ * @param s x-path string * @return list of string steps */ private static List<String> splitPath(String s) { ArrayList<String> parts = new ArrayList<String>(); StringBuffer b = new StringBuffer(); int insideIndex = 0; for (int pos = 0; pos < s.length(); pos++) { if (s.charAt(pos) == '/' && insideIndex == 0) { parts.add(b.toString()); b = new StringBuffer(); } else { if (s.charAt(pos) == '[') { insideIndex++; } else if (s.charAt(pos) == ']') { insideIndex--; } b.append(s.charAt(pos)); } } parts.add(b.toString()); return parts; }
From source file:editor.util.URLUtil.java
public static String sendPost(String url, String data) throws Exception { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); // Send post request con.setDoOutput(true);/*from w w w .j av a 2s .co m*/ DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(data); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); }
From source file:com.npower.dm.util.DMUtil.java
/** * Append a parameter into URL//from www . j av a2 s . c o m * @param url * @param parameterName * @param parameterValue * @return */ public static String appendParameter(String url, String parameterName, String parameterValue) { StringBuffer result = new StringBuffer(url); if (StringUtils.isEmpty(parameterName)) { return result.toString(); } if (url.indexOf('?') > 0) { result.append('&'); } else { result.append('?'); } result.append(parameterName); result.append('='); try { result.append(URLEncoder.encode(parameterValue, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } return result.toString(); }
From source file:com.thalesgroup.hudson.plugins.klocwork.util.KloMetricUtil.java
public static String getMessageSelectedSeverties(KloConfig kloConfig) { StringBuffer sb = new StringBuffer(); if (kloConfig.getConfigSeverityEvaluation().isAllSeverities()) { sb.append("with all severities"); return sb.toString(); }//from ww w. j a va 2 s . c o m if (kloConfig.getConfigSeverityEvaluation().isHighSeverity()) { sb.append(" and "); sb.append("severity 'high severity'"); } if (kloConfig.getConfigSeverityEvaluation().isLowSeverity()) { sb.append(" and "); sb.append("severity 'low severity'"); } if (sb.length() != 0) sb.delete(0, 5); return sb.toString(); }
From source file:gov.gtas.parsers.util.FlightUtils.java
public static String padFlightNumberWithZeroes(String fn) { if (StringUtils.isBlank(fn)) { return null; }/* www. ja v a 2s. c o m*/ StringBuffer buff = new StringBuffer(); for (int j = 0; j < MAX_FLIGHT_NUM_LENG - fn.length(); j++) { buff.append("0"); } buff.append(fn); return buff.toString(); }
From source file:Main.java
private static String hexify(byte bytes[]) { char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; StringBuffer buf = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; ++i) { buf.append(hexDigits[(bytes[i] & 0xf0) >> 4]); buf.append(hexDigits[bytes[i] & 0x0f]); }/*from w w w . ja va2 s . com*/ return buf.toString(); }
From source file:Main.java
/** * Prints each object in the array with commas between them. * Nulls will print as "null". A null array will cause NPE. */// ww w . j ava2 s. co m public static String arrayToString(Object[] array) { StringBuffer outputString = new StringBuffer(100); for (int i = 0, n = array.length; i < n; i++) { if (i > 0) outputString.append(", "); outputString.append(array[i]); } return outputString.toString(); }
From source file:Main.java
private static String constructString(int[] unicodeChars) { StringBuffer buffer = new StringBuffer(); if (unicodeChars != null) { for (int i = 0; i < unicodeChars.length; i++) { buffer.append((char) unicodeChars[i]); }/* w w w.jav a 2 s. co m*/ } return buffer.toString(); }
From source file:Main.java
/** * Takes String[] of tokens, and String delimiter as input and returns * joined String//from w w w.j ava2 s .c o m * * @param sourceArray * , input tokens in String array * @param delimiter * , delimiter to join on * @return String , string of tokens joined by delimiter */ public static String joinString(String[] sourceArray, String delimiter) { if (sourceArray == null || delimiter == null) { return ""; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < sourceArray.length - 1; i++) { sb.append(sourceArray[i]).append(delimiter); } sb.append(sourceArray[sourceArray.length - 1]); return sb.toString(); }