List of usage examples for java.lang StringBuilder append
@Override public StringBuilder append(double d)
From source file:Main.java
public static String printBytes(byte[] data) { StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < data.length; i++) { String hex = Integer.toHexString(data[i]); if (hex.length() == 1) hex = "0" + hex; else//from ww w . j a va2s . c om hex = hex.substring(hex.length() - 2); sb.append(hex); if (i < data.length - 1) { if ((i + 1) % 30 == 0) sb.append("\n "); else if ((i + 1) % 10 == 0) sb.append(" "); else sb.append(" "); } } sb.append("]"); return sb.toString(); }
From source file:Main.java
public static String printBundle(Bundle bundle) { StringBuilder sb = new StringBuilder(); sb.append("Bundle: "); if (bundle != null) { sb.append(bundle.toString());//from w ww . ja v a 2 s . c om sb.append("\n"); Set<String> keys = bundle.keySet(); for (String it : keys) { sb.append(" "); sb.append(it); sb.append(": "); sb.append(bundle.get(it).toString()); sb.append("\n"); } } else { sb.append("(null)"); } return sb.toString(); }
From source file:Main.java
/** * Generates a discover request./*from w ww. ja v a 2 s . c om*/ * * @param requestType request type * @return XMLA request */ public static String generateXmlaDiscoverRequest(String requestType) { final StringBuilder buf = new StringBuilder(); buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n").append("<SOAP-ENV:Envelope\n") .append(" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n") .append(" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n") .append(" <SOAP-ENV:Body>\n") .append(" <Discover xmlns=\"urn:schemas-microsoft-com:xml-analysis\"\n") .append(" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n") .append(" <RequestType>").append(requestType).append("</RequestType>\n") .append(" <Restrictions>\n").append(" <RestrictionList/>\n").append(" </Restrictions>\n") .append(" <Properties>\n").append(" <PropertyList/>\n").append(" </Properties>\n") .append(" </Discover>\n").append(" </SOAP-ENV:Body>\n").append("</SOAP-ENV:Envelope>"); return buf.toString(); }
From source file:Main.java
public static <T> T unsupported(final String op, final Object... a) { final StringBuilder msg = new StringBuilder(INITIAL_SIZE); msg.append("Nobody told me how to run "); msg.append(op);//from www . j a v a 2 s . c o m if (a.length > 0) { msg.append(" with parameters of class: "); for (final Object o : a) { msg.append(o == null ? "null" : o.getClass().getSimpleName()); msg.append(", "); } msg.delete(msg.length() - 2, msg.length()); msg.append('.'); } throw new UnsupportedOperationException(msg.toString()); }
From source file:Main.java
private static void copyFile(Context ctx, String filename) throws IOException { InputStream in = null;//from ww w . jav a 2 s . c om OutputStream out = null; in = ctx.getApplicationContext().getAssets().open(filename); StringBuilder newFileName = new StringBuilder(); newFileName.append(DATA_DIR).append(ctx.getPackageName()).append("/").append(filename); out = new FileOutputStream(newFileName.toString()); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); in = null; out.flush(); out.close(); out = null; }
From source file:Main.java
private static void appendZeroPadded(final StringBuilder builder, int value) { if (value < 10) { builder.append('0'); }// w ww . j a v a 2s . co m builder.append(value); }
From source file:Main.java
private static <T> String formatCollection(Collection<T> collection, int maxLen) { StringBuilder builder = new StringBuilder(); builder.append("["); boolean first = true; for (T elem : collection) { String val = ((first) ? ", " : "") + ((elem != null) ? elem.toString() : "null"); first = false;/* ww w .j a va 2 s . co m*/ if ((builder.length() + val.length()) > maxLen - "...]".length()) { builder.append("..."); break; } else { builder.append(val); } } builder.append("]"); return builder.toString(); }
From source file:co.runrightfast.metrics.MetricType.java
public static String metricName(@NonNull final MetricType metricType, final String... names) { notEmpty(names);//from w ww . jav a 2 s . c om checkArgument(!Arrays.stream(names).filter(StringUtils::isBlank).findFirst().isPresent(), "any of the names cannot be blank"); final StringBuilder sb = new StringBuilder(64); sb.append(metricType.name()); Arrays.stream(names).forEach(n -> sb.append('.').append(n)); return sb.toString(); }
From source file:Main.java
/** * json//from w w w . j a v a2 s .c o m * @param params * @return */ public static String buildJsonString(Map<String, Object> params) { if (params == null || params.size() == 0) return null; Set<Entry<String, Object>> setEntry = params.entrySet(); StringBuilder str = new StringBuilder(); str.append("{"); for (Entry<String, Object> entry : setEntry) { str.append("\""); str.append(entry.getKey()); str.append("\""); str.append(":"); if (entry.getValue() instanceof String) { str.append("\""); } str.append(entry.getValue()); if (entry.getValue() instanceof String) { str.append("\""); } str.append(","); } str.setCharAt(str.length() - 1, '}'); return str.toString(); }
From source file:Main.java
public static String dumpJPEG(byte[] jpeg) { StringBuilder sb = new StringBuilder("jpeg "); if (jpeg == null) { sb.append("<null>"); } else {//from www.java 2s . c o m sb.append("length=" + jpeg.length); } return sb.toString(); }