List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start, int end)
From source file:org.kuali.ext.mm.utility.BeanDDCreator.java
public static String camelCaseToString(String className) { StringBuffer newName = new StringBuffer(className); // upper case the 1st letter newName.replace(0, 1, newName.substring(0, 1).toUpperCase()); // loop through, inserting spaces when cap for (int i = 0; i < newName.length(); i++) { if (Character.isUpperCase(newName.charAt(i))) { newName.insert(i, ' '); i++;/*from w w w . jav a2 s .c o m*/ } } return newName.toString().trim().replace("Uc", "UC"); }
From source file:Main.java
/** * Removes all occurrences of the specified stylename in the given style and * returns the updated style. Trailing semicolons are preserved. *///from ww w. j a va 2 s .com public static String removeStylename(String style, String stylename) { StringBuffer buffer = new StringBuffer(); if (style != null) { String[] tokens = style.split(";"); for (int i = 0; i < tokens.length; i++) { if (!tokens[i].equals(stylename)) { buffer.append(tokens[i] + ";"); } } } return (buffer.length() > 1) ? buffer.substring(0, buffer.length() - 1) : buffer.toString(); }
From source file:org.rapidcontext.app.plugin.cmdline.CmdLineExecProcedure.java
/** * Analyzes the error output buffer from a process and adds the * relevant log messages//from w w w . ja v a 2s. c o m * * @param cx the procedure call context * @param buffer the process error output buffer */ private static void log(CallContext cx, StringBuffer buffer) { int pos; while ((pos = buffer.indexOf("\n")) >= 0) { String text = buffer.substring(0, pos).trim(); if (text.length() > 0 && text.charAt(0) == '#') { if (cx.getCallStack().height() <= 1) { Matcher m = PROGRESS_PATTERN.matcher(text); if (m.find()) { double progress = Double.parseDouble(m.group(1)); cx.setAttribute(CallContext.ATTRIBUTE_PROGRESS, Double.valueOf(progress)); } } } else { cx.log(buffer.substring(0, pos)); } buffer.delete(0, pos + 1); } }
From source file:FileUtils.java
public static String relativePath(String fromPath, String toPath, boolean fromIsDirectory, char separatorChar) { ArrayList<String> fromElements = splitPath(fromPath); ArrayList<String> toElements = splitPath(toPath); while (!fromElements.isEmpty() && !toElements.isEmpty()) { if (!(fromElements.get(0).equals(toElements.get(0)))) { break; }/*from w ww .ja v a 2 s .c om*/ fromElements.remove(0); toElements.remove(0); } StringBuffer result = new StringBuffer(); for (int i = 0; i < fromElements.size() - (fromIsDirectory ? 0 : 1); i++) { result.append(".."); result.append(separatorChar); } for (String s : toElements) { result.append(s); result.append(separatorChar); } return result.substring(0, result.length() - 1); }
From source file:Main.java
public static String getMD5(String str) { MessageDigest messageDigest = null; try {//w ww . jav a 2s . co m messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); } catch (NoSuchAlgorithmException e) { } catch (UnsupportedEncodingException e) { } byte[] byteArray = messageDigest.digest(); StringBuffer md5StrBuff = new StringBuffer(); for (int i = 0; i < byteArray.length; i++) { if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) { md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); } else { md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i])); } } return md5StrBuff.substring(8, 24).toString(); }
From source file:Main.java
public static String getMD5Str(String str) { MessageDigest messageDigest = null; try {// w w w .j a va2 s . com messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(str.getBytes("UTF-8")); } catch (NoSuchAlgorithmException e) { System.out.println("NoSuchAlgorithmException caught!"); } catch (UnsupportedEncodingException e) { } byte[] byteArray = messageDigest.digest(); StringBuffer md5StrBuff = new StringBuffer(); for (int i = 0; i < byteArray.length; i++) { if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); else md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i])); } return md5StrBuff.substring(0, 24).toString().toUpperCase(); }
From source file:org.glite.slcs.shibclient.TestShibbolethClient.java
public static String getDN(StringBuffer response) { String dn = null;//from w w w . j a va 2 s . c om int start = response.indexOf("<DN>"); if (start != -1) { start += "<DN>".length(); int stop = response.indexOf("</DN>", start); if (stop != -1) { dn = response.substring(start, stop); } else { System.err.println("</DN> not found!"); } } else { System.err.println("<DN> not found!"); } return dn; }
From source file:org.apache.axiom.attachments.impl.PartFactory.java
/** * Parse the header into a name and value pair. * Add the name value pair to the map.//w ww . j a v a2 s.co m * @param header StringBuffer * @param headers Map */ private static void readHeader(StringBuffer header, Map headers) { int delimiter = header.indexOf(":"); String name = header.substring(0, delimiter).trim(); String value = header.substring(delimiter + 1, header.length()).trim(); if (log.isDebugEnabled()) { log.debug("addHeader: (" + name + ") value=(" + value + ")"); } Header headerObj = new Header(name, value); // Use the lower case name as the key String key = name.toLowerCase(); headers.put(key, headerObj); }
From source file:org.ops4j.pax.runner.commons.properties.SystemPropertyUtils.java
/** * Resolve ${...} placeholders in the given text, replacing them with corresponding property values or system * property values.//from w ww .ja v a2s.com * * @param text the String to resolve * @param properties properties to be searched beside system properties * * @return the resolved String * * @see #PLACEHOLDER_PREFIX * @see #PLACEHOLDER_SUFFIX */ public static String resolvePlaceholders(final String text, final Properties properties) { if (text == null) { return null; } StringBuffer buf = new StringBuffer(text); int startIndex = buf.indexOf(PLACEHOLDER_PREFIX); while (startIndex != -1) { int endIndex = buf.indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length()); if (endIndex != -1) { String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex); int nextIndex = endIndex + PLACEHOLDER_SUFFIX.length(); try { String propVal = properties.getProperty(placeholder); if (propVal == null) { propVal = System.getProperty(placeholder); if (propVal == null) { // Fall back to searching the system environment. propVal = System.getenv(placeholder); } } if (propVal != null) { buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal); nextIndex = startIndex + propVal.length(); } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Could not resolve placeholder '" + placeholder + "' in [" + text + "] as system property: neither system property nor environment variable found"); } } } catch (Throwable ex) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Could not resolve placeholder '" + placeholder + "' in [" + text + "] as system property: " + ex); } } startIndex = buf.indexOf(PLACEHOLDER_PREFIX, nextIndex); } else { startIndex = -1; } } return buf.toString(); }
From source file:org.exoplatform.wiki.rendering.internal.parser.confluence.ConfluenceLinkReferenceParser.java
public static String divideOn(StringBuffer buffer, char divider) { if (buffer.length() == 0) { return null; }/*from w w w. j av a 2 s .c om*/ int i = buffer.indexOf(Character.toString(divider)); if (i < 0) { return null; } if (i == 0) { buffer.deleteCharAt(0); return null; } String body = buffer.substring(0, i); buffer.delete(0, i + 1); return body; }