List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:TimeUtils.java
public static String toBinaryText(StringBuffer buf) { boolean bufHasBinary = false; int len = buf.length(); for (int i = 0; i < len; i++) { if (buf.charAt(i) < ' ') { bufHasBinary = true;//from www. j a v a 2s. c o m break; } } if (bufHasBinary) { StringBuffer formatedDataBuf = new StringBuffer(); for (int k = 0; k < len; k++) { formatedDataBuf.append(printable(buf.charAt(k))); } formatedDataBuf.append(" 0x["); for (int k = 0; k < len; k++) { formatedDataBuf.append(toHex00String(buf.charAt(k))).append(' '); } formatedDataBuf.append("]"); buf = formatedDataBuf; } return buf.toString(); }
From source file:com.ai.smart.common.helper.util.RequestUtils.java
/** * /* ww w . ja va 2 s. com*/ * <p> * HttpServletRequest.getRequestURL+"?"+HttpServletRequest.getQueryString * * @param request * @return */ public static String getLocation(HttpServletRequest request) { UrlPathHelper helper = new UrlPathHelper(); StringBuffer buff = request.getRequestURL(); String uri = request.getRequestURI(); String origUri = helper.getOriginatingRequestUri(request); buff.replace(buff.length() - uri.length(), buff.length(), origUri); String queryString = helper.getOriginatingQueryString(request); if (queryString != null) { buff.append("?").append(queryString); } return buff.toString(); }
From source file:Main.java
/** /* FindAndReplace - finds and replaces in StringBuffer theSBuffer, /* starts at fromIndex, returns index of find. * //from ww w . j a v a2s .c om * @param findString, replaceString, sBuffer, index * @return int * */ public static int FindAndReplace(String find, String replace, StringBuffer theSBuffer, int fromIndex) { String interString; int theIndex, i, j; if (find == null) return -1; if (replace == null) return -1; if (theSBuffer == null) return -1; int theSBufferLength = theSBuffer.length(); int findLength = find.length(); if (theSBufferLength == 0) return -1; if (findLength == 0) return -1; if (theSBufferLength < findLength) return -1; if ((fromIndex < 0) || (fromIndex > theSBufferLength)) return -1; interString = theSBuffer.toString(); theIndex = interString.indexOf(find, fromIndex); if (theIndex == -1) return -1; //// on 9210 the following code ... for (i = theIndex; i < theSBufferLength - findLength; i++) { theSBuffer.setCharAt(i, theSBuffer.charAt(i + findLength)); } for (j = theSBufferLength - 1; j >= (theSBufferLength - findLength); j--) { theSBuffer.setCharAt(j, (char) (0)); } int newLength = theSBufferLength - findLength; theSBuffer.setLength(newLength); theSBuffer.insert(theIndex, replace); return theIndex; }
From source file:Main.java
public static String percent(double value1, double value2, int decimalPointAfterLength, boolean replaceWithZero, boolean removePercent) { StringBuffer buffString = new StringBuffer(); buffString.append("#"); if (decimalPointAfterLength > 0) { buffString.append("."); }/*from w w w .j av a 2 s .c o m*/ for (int w = 0; w < decimalPointAfterLength; w++) { buffString.append(replaceWithZero ? "0" : "#"); } buffString.append("%"); if (buffString.length() > 0) { String result = new DecimalFormat(buffString.toString()).format(value1 / value2); if (removePercent && result.length() > 0) { result = result.substring(0, result.length() - 1); } return result; } else { return null; } }
From source file:com.doculibre.constellio.wicket.utils.SimpleParamsUtils.java
public static String appendParams(String url, SimpleParams simpleParams) { StringBuffer sb = new StringBuffer(url); for (String paramName : simpleParams.keySet()) { for (String paramValue : simpleParams.getList(paramName)) { if (sb.indexOf("?") == -1 && StringUtils.isNotBlank(url)) { sb.append("?"); } else if (sb.length() > 0) { sb.append("&"); }// www. j a v a 2 s .c om sb.append(paramName + "=" + paramValue); } } return sb.toString(); }
From source file:FillViewportHeightDemo.java
private static String getNextString(int count) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < 5; i++) { buf.append(String.valueOf(count)); buf.append(","); }/* w w w . j ava 2s. com*/ // remove last newline buf.deleteCharAt(buf.length() - 1); return buf.toString(); }
From source file:com.youTransactor.uCube.Tools.java
public static String parseVersion(byte[] data) { StringBuffer buffer = new StringBuffer(); if (data != null) { for (int i = 0; i < data.length; i++) { if (buffer.length() > 0) { buffer.append('.'); }/*ww w .ja v a2 s . com*/ buffer.append(String.valueOf(data[i])); } } return buffer.toString(); }
From source file:Main.java
public static String wrapString(String s, int maxchar) { StringBuffer str = new StringBuffer(); while (s.length() > 0) { s = s.trim();//from w ww.j av a2 s . c o m int pos = -1; for (int i = 0; i < s.length() && (i < maxchar || pos < 0); i++) { if (s.charAt(i) == ' ') { pos = i; } } if (pos > 0) { str.append((str.length() > 0 ? "\n" : "") + s.substring(0, pos)); s = s.substring(pos + 1); } else { str.append(s); s = ""; } } return str.toString(); }
From source file:net.duckling.ddl.util.StringUtil.java
License:asdf
public static String getRandomString(int length) { StringBuffer buffer = new StringBuffer("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"); StringBuffer sb = new StringBuffer(); Random r = new Random(); int range = buffer.length(); for (int i = 0; i < length; i++) { sb.append(buffer.charAt(r.nextInt(range))); }/* ww w .j a v a2s . c o m*/ return sb.toString(); }
From source file:TextUtilities.java
/** * Pads the given String on both sides equally (if possible) with the given * character until it's <code>length</code> characters long. If the given * String's size is already <code>length</code> or larger, the given * string is returned as is.// ww w . j av a2s . c om */ public static String padSides(String s, char c, int length) { if (s.length() >= length) return s; StringBuffer buf = new StringBuffer(s); for (int i = s.length(); i < length - 1; i += 2) { buf.insert(0, c); buf.append(c); } if (buf.length() < length) buf.insert(0, c); return buf.toString(); }