List of usage examples for java.lang StringBuilder StringBuilder
@HotSpotIntrinsicCandidate
public StringBuilder()
From source file:Main.java
private static String byte2String(byte[] b) { StringBuilder hs = new StringBuilder(); String stmp;/*from ww w . j a v a 2 s . c o m*/ for (int n = 0; b != null && n < b.length; n++) { stmp = Integer.toHexString(b[n] & 0XFF); if (stmp.length() == 1) hs.append('0'); hs.append(stmp); } return hs.toString().toUpperCase(Locale.CHINA); }
From source file:Main.java
public static final String formatStackTrace(final StackTraceElement pStackTraceElement) { return new StringBuilder().append(pStackTraceElement.getClassName()).append('.') .append(pStackTraceElement.getMethodName()).append('(').append(pStackTraceElement.getFileName()) .append(':').append(pStackTraceElement.getLineNumber()).append(')').toString(); }
From source file:Main.java
public static String appString(String[] colums, String[] values) { StringBuilder builder = new StringBuilder(); int size = colums.length; for (int i = 0; i < size; i++) { String value = values[i]; if (value != null) { if (value.trim().length() > 0) { builder.append(colums[i] + ":" + value + "\n"); }/*w ww .j a v a2s.co m*/ } } return builder.toString(); }
From source file:Main.java
public static String bytesToIpPortString(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 4; i++) { int Ip;/*ww w . j ava 2 s.com*/ if (bytes[i] < 0) { Ip = bytes[i] + 256; } else { Ip = bytes[i]; } sb.append(String.valueOf(Ip)); if (i < 3) { sb.append("."); } else { sb.append(":"); } } int portHigh = (bytes[5] >= 0 ? bytes[5] : bytes[5] + 256); int portLow = (bytes[4] >= 0 ? bytes[4] : bytes[4] + 256); int port = portHigh * 256 + portLow; sb.append(String.valueOf(port)); return sb.toString(); }
From source file:Main.java
public static String dumpStack(Thread t) { StringBuilder sb = new StringBuilder(); sb.append(t.getName() + "[" + t.getId() + "] - " + t.getState() + ":\n"); for (StackTraceElement ste : t.getStackTrace()) { sb.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")\n"); }//from w w w .j a va 2s .co m return sb.toString(); }
From source file:Main.java
public static String putInString(String source, String placement, int gap) { StringBuilder builder = new StringBuilder(); int i = 0;// w w w. j a v a2 s. c o m while (i + gap < source.length()) { builder.append(source.substring(i, i + gap)); builder.append(placement); i += gap; } builder.append(source.substring(i)); return builder.toString(); }
From source file:Main.java
public static String hideEmail(String mail) { StringBuilder stringBuilder = new StringBuilder(); if (mail.lastIndexOf("@") > 0) { int index = mail.lastIndexOf("@"); if (index == 1) { stringBuilder.append(mail.substring(0, 1)); stringBuilder.append("***"); stringBuilder.append(mail.substring(index)); } else {//from w w w.j av a 2s .co m stringBuilder.append(mail.substring(0, 1)); stringBuilder.append("***"); stringBuilder.append(mail.substring(index - 1)); } } else { return mail; } String mailHidden = stringBuilder.toString(); if (mailHidden.length() > 20) { return mailHidden.substring(0, 20) + "..."; } else { return mailHidden; } }
From source file:Main.java
public static String KJencrypt(String str) { char[] cstr = str.toCharArray(); StringBuilder hex = new StringBuilder(); for (char c : cstr) { hex.append((char) (c + 5)); }/*w ww. j ava 2 s .c om*/ return hex.toString(); }
From source file:Main.java
private static String splitCamelToHuman(final String source) { StringBuilder target = new StringBuilder(); boolean isFirstChar = true; for (int i = 0; i < source.length(); i++) { Character ch = source.charAt(i); if (Character.isUpperCase(ch)) { target.append(" "); if (isFirstChar) { target.append(ch);/*from ww w.j av a 2s . c o m*/ isFirstChar = false; } else { target.append(Character.toLowerCase(ch)); } } else { target.append(ch); } } return target.toString(); }
From source file:Main.java
public static String getComponentName(ResolveInfo resolveInfo) { return new StringBuilder().append(resolveInfo.activityInfo.packageName).append("/") .append(resolveInfo.activityInfo.name).toString(); }