List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:Main.java
public static String toMacFormat(String mac) { if (mac.length() == 12) { StringBuffer sb = new StringBuffer(mac); sb.insert(10, ':'); sb.insert(8, ':'); sb.insert(6, ':'); sb.insert(4, ':'); sb.insert(2, ':'); return sb.toString(); }//from w ww . j av a 2 s.c o m return ""; }
From source file:Main.java
/** * MMdd -> MM-dd//w w w .j a v a 2 s . c om * * @param MMdd * @return */ public static String formatMMddDash(String MMdd) { if (null != MMdd && MMdd.length() == 4) { StringBuffer sb = new StringBuffer(MMdd); sb.insert(2, "-"); return sb.toString(); } return MMdd; }
From source file:Main.java
/** * @comment_sp Agrega XMLNamespace/*from w ww . ja v a2 s . c o m*/ * @comment_ko addXMLNamespace * @param source * @param xmlNamespace * @return */ public static byte[] addXMLNamespace(byte source[], String xmlNamespace) { byte oldContent[] = new byte[source.length]; System.arraycopy(source, 0, oldContent, 0, source.length); String s = new String(oldContent); String inputNamespace = " xmlns=\"" + xmlNamespace + "\""; int start = s.indexOf("?>"); int fromIndex = s.indexOf("<", start); int toIndex = s.indexOf(">", fromIndex); StringBuffer sb = new StringBuffer(s); sb.insert(toIndex, inputNamespace); String input = new String(sb); return input.getBytes(); }
From source file:Main.java
public static String truncateChange(String change, boolean isPercentChange) { String weight = change.substring(0, 1); String ampersand = ""; if (isPercentChange) { ampersand = change.substring(change.length() - 1, change.length()); change = change.substring(0, change.length() - 1); }//from w w w . j a v a2 s . c o m change = change.substring(1, change.length()); double round = (double) Math.round(Double.parseDouble(change) * 100) / 100; change = String.format("%.2f", round); StringBuffer changeBuffer = new StringBuffer(change); changeBuffer.insert(0, weight); changeBuffer.append(ampersand); change = changeBuffer.toString(); return change; }
From source file:Main.java
public static String getBeforeExtension(String path, String insert) { if (getFileExtension(path).equals("") || getFileExtension(path) == null) { return null; }/*from w w w . java2 s . co m*/ StringBuffer sb = new StringBuffer(path); int index = path.lastIndexOf("."); sb.insert(index, insert); return sb.toString(); }
From source file:ju.ehealthservice.utils.ImageHandler.java
public static String formatString(byte[] bin) { StringBuffer data = new StringBuffer(Base64.encodeBase64String(bin)); data.insert(0, Constants.IMAGE_HEADER); return data.toString(); }
From source file:Main.java
/**In order to create a 64 bit binary string, the zero-padding on the left of the value is carried out * @param value the string to pad/*from w ww .j a v a 2s.co m*/ * @return Padded string */ public static String padding64(String value) { StringBuffer sb = new StringBuffer(); sb.append(value); for (int i = 0; i < 64 - value.length(); i++) { sb.insert(0, "0"); } return sb.toString(); }
From source file:org.mule.util.ArrayUtils.java
/** * Like {@link #toString(Object)} but considers at most <code>maxElements</code> * values; overflow is indicated by an appended "[..]" ellipsis. *///from ww w . j a va 2 s.c o m public static String toString(Object array, int maxElements) { String result; Class componentType = array.getClass().getComponentType(); if (Object.class.isAssignableFrom(componentType)) { result = ArrayUtils.toString((ArrayUtils.subarray((Object[]) array, 0, maxElements))); } else if (componentType.equals(Boolean.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((boolean[]) array, 0, maxElements))); } else if (componentType.equals(Byte.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((byte[]) array, 0, maxElements))); } else if (componentType.equals(Character.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((char[]) array, 0, maxElements))); } else if (componentType.equals(Short.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((short[]) array, 0, maxElements))); } else if (componentType.equals(Integer.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((int[]) array, 0, maxElements))); } else if (componentType.equals(Long.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((long[]) array, 0, maxElements))); } else if (componentType.equals(Float.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((float[]) array, 0, maxElements))); } else if (componentType.equals(Double.TYPE)) { result = ArrayUtils.toString((ArrayUtils.subarray((double[]) array, 0, maxElements))); } else { throw new IllegalArgumentException("Unknown array service type: " + componentType.getName()); } if (Array.getLength(array) > maxElements) { StringBuffer buf = new StringBuffer(result); buf.insert(buf.length() - 1, " [..]"); result = buf.toString(); } return result; }
From source file:Main.java
public static String getComponentPath(Component c) { StringBuffer sb = new StringBuffer(); Component current = c;/*from www. ja va2 s. c om*/ boolean isFirst = true; while (current.getParent() != null) { sb.insert(0, (isFirst ? "" : ".") + current.getClass().getSimpleName()); isFirst = false; current = current.getParent(); } return sb.toString(); }
From source file:Util.java
public static String dateToIsoDateTime(String date) { StringBuffer sb = new StringBuffer(date); if (date.length() >= 8) { //20070101 -> 2007-01-01 //insert hyphens between year, month, and day sb.insert(4, '-'); sb.insert(7, '-'); //2007-01-01T173012 -> 2007-01-01T17:30:12 if (date.length() >= 15) { //insert colons between hours, minutes, and seconds sb.insert(13, ':'); sb.insert(16, ':'); //2007-01-01T17:30:12 -> 2007-01-01T17:30:12.000 //append milliseconds if (sb.toString().length() > 19) sb.insert(20, ".000"); else/*from ww w . j a va 2s . co m*/ sb.append(".000"); //2007-01-01T17:30:12.000 -> 2007-01-01T17:30:12.000Z //append UTC indicator if exists if (date.length() > 15 && date.charAt(15) == 'Z') sb.append('Z'); } if (sb.length() > 19) sb.setLength(19); } return sb.toString(); }