List of usage examples for java.lang StringBuffer setCharAt
@Override public synchronized void setCharAt(int index, char ch)
From source file:UnixCrypt.java
/** * <P>//from w ww . j av a 2 s .c o m * Encrypt a password given the cleartext password and a "salt". * </P> * * @param salt * A two-character string representing the salt used to iterate * the encryption engine in lots of different ways. If you are * generating a new encryption then this value should be * randomised. * @param original * The password to be encrypted. * @return A string consisting of the 2-character salt followed by the * encrypted password. */ public static final String crypt(String salt, String original) { while (salt.length() < 2) salt += "A"; StringBuffer buffer = new StringBuffer(" "); char charZero = salt.charAt(0); char charOne = salt.charAt(1); buffer.setCharAt(0, charZero); buffer.setCharAt(1, charOne); int Eswap0 = con_salt[(int) charZero]; int Eswap1 = con_salt[(int) charOne] << 4; byte key[] = new byte[8]; for (int i = 0; i < key.length; i++) key[i] = (byte) 0; for (int i = 0; i < key.length && i < original.length(); i++) { int iChar = (int) original.charAt(i); key[i] = (byte) (iChar << 1); } int schedule[] = des_set_key(key); int out[] = body(schedule, Eswap0, Eswap1); byte b[] = new byte[9]; intToFourBytes(out[0], b, 0); intToFourBytes(out[1], b, 4); b[8] = 0; for (int i = 2, y = 0, u = 0x80; i < 13; i++) { for (int j = 0, c = 0; j < 6; j++) { c <<= 1; if (((int) b[y] & u) != 0) c |= 1; u >>>= 1; if (u == 0) { y++; u = 0x80; } buffer.setCharAt(i, (char) cov_2char[c]); } } return (buffer.toString()); }
From source file:gov.nih.nci.cabig.ctms.lang.StringTools.java
/** * Normalizes the whitespace in the given buffer in-place. * This means that the whitespace is stripped from the head and the tail * and any contiguous stretches of whitespace are converted into a single * space.//from w ww . java2 s .c om * * @param toNormalize * @return the passed-in buffer */ public static StringBuffer normalizeWhitespace(StringBuffer toNormalize) { if (toNormalize == null) return null; // start with this value == true to completely remove leading whitespace boolean prevIsWhitespace = true; for (int i = 0; i < toNormalize.length(); i++) { if (Character.isWhitespace(toNormalize.charAt(i))) { if (prevIsWhitespace) { toNormalize.deleteCharAt(i); i--; } else { toNormalize.setCharAt(i, ' '); prevIsWhitespace = true; } } else { prevIsWhitespace = false; } } // remove (at most) one trailing ' ' if (toNormalize.length() > 0 && toNormalize.charAt(toNormalize.length() - 1) == ' ') toNormalize.deleteCharAt(toNormalize.length() - 1); return toNormalize; }
From source file:org.dhatim.cdr.annotation.Configurator.java
private static String getPropertyName(Method method) { if (!method.getName().startsWith("set")) { return null; }//from w ww . ja va 2s . c o m StringBuffer methodName = new StringBuffer(method.getName()); if (methodName.length() < 4) { return null; } methodName.delete(0, 3); methodName.setCharAt(0, Character.toLowerCase(methodName.charAt(0))); return methodName.toString(); }
From source file:org.dhatim.util.ClassUtil.java
public static String toSetterName(String property) { StringBuffer setterName = new StringBuffer(); // Add the property string to the buffer... setterName.append(property);//from w w w . jav a2s.c o m // Uppercase the first character... setterName.setCharAt(0, Character.toUpperCase(property.charAt(0))); // Prefix with "set"... setterName.insert(0, "set"); return setterName.toString(); }
From source file:org.dhatim.util.ClassUtil.java
public static String toGetterName(String property) { StringBuffer getterName = new StringBuffer(); // Add the property string to the buffer... getterName.append(property);/* www. j av a 2s .c o m*/ // Uppercase the first character... getterName.setCharAt(0, Character.toUpperCase(property.charAt(0))); // Prefix with "get"... getterName.insert(0, "get"); return getterName.toString(); }
From source file:org.dhatim.util.ClassUtil.java
public static String toIsGetterName(String property) { StringBuffer getterName = new StringBuffer(); // Add the property string to the buffer... getterName.append(property);//from w w w.j av a 2s.com // Uppercase the first character... getterName.setCharAt(0, Character.toUpperCase(property.charAt(0))); // Prefix with "is"... getterName.insert(0, "is"); return getterName.toString(); }
From source file:org.pmedv.core.util.StringUtil.java
/** * <p>/*from ww w. j a v a2 s .c om*/ * Converts a straight text to a text with line breaks depending * on the length of a line. * </p> * <p> * If the character at <b>lineWidth</b> is not a whitespace, * the function steps back inside the character array until a * whitespace is found. * </p> * <p> * If the param html is set to true, the output string is embedded between * <html></html> tags and the line breaks are printed as <br> * instead of \n. This is for example useful for tooltip and html panel display * of the text. * <p> * * @param originalText the text to insert line breaks into * @param lineWidth the maximum length of the line (the expected position of the linebreak) * @param html force html output * * @return the converted String containing line breaks */ public static String insertLineBreaks(String originalText, int lineWidth, boolean html) { if (originalText == null) return ""; if (originalText.length() <= lineWidth) return originalText; StringBuffer text = new StringBuffer(originalText); if (html) { text.insert(0, Tags.HTML_OPEN); } for (int i = 1; i < text.length(); i++) { if (i % lineWidth == 0) { int j = i; while (text.charAt(j--) != ' ' && j > 1) ; // TODO : Remove hard coded line break and do some platform checking if (html) text.insert(j + 1, Tags.NEWLINE); else text.setCharAt(j + 1, '\n'); } } if (html) { text.append(Tags.HTML_CLOSE); } return text.toString(); }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Convert into lowercase with uppercase initial. * * @param string Word like "hello".//from www . ja v a2 s . co m * @return Word like "Hello" */ public static String toInitialCase(String string) { if (string.isEmpty()) { return string; } StringBuffer lower = new StringBuffer(string.toLowerCase()); lower.setCharAt(0, Character.toUpperCase(lower.charAt(0))); return lower.toString(); }
From source file:TextUtilities.java
/** * Breaks the specified text into lines no longer than the specified length, * without breaking words. The breaking is done by inserting newlines at * appropriate locations. Note that if there are words longer than * <code>maxLength</code>, they will not be broken. *//*from w ww . ja v a 2s . com*/ public static String breakIntoLines(String text, int maxLength) { StringBuffer buf = new StringBuffer(text); text = text + " "; // Fake an extra space at the end to simplify the algorithm int lastNewline = -1; // The index of the last newline int lastSpace = -1; // The index of the last space int curSpace; // The index of the current space while ((curSpace = text.indexOf(' ', lastSpace + 1)) != -1) { if ((curSpace - lastNewline - 1 > maxLength) && (lastSpace > lastNewline)) { // lastSpace == lastNewline means the current word is longer than maxLength buf.setCharAt(lastSpace, '\n'); lastNewline = lastSpace; } lastSpace = curSpace; } return buf.toString(); }
From source file:jdiff.API.java
/** * Convert all HTML tags to text by stuffing text into the HTML tag * to stop it being an HTML or XML tag. E.g. "<code>foo</code>" * becomes "lEsS_tHaNcode>foolEsS_tHaN/code>". Replace all < * characters/*from w w w. jav a 2 s .c om*/ * with the string "lEsS_tHaN". Also replace & character with the * string "aNd_cHaR" to avoid text entities. Also replace " * character with the * string "qUoTe_cHaR". */ public static String hideHTMLTags(String htmlText) { StringBuffer sb = new StringBuffer(htmlText); int i = 0; while (i < sb.length()) { if (sb.charAt(i) == '<') { sb.setCharAt(i, 'l'); sb.insert(i + 1, "EsS_tHaN"); } else if (sb.charAt(i) == '&') { sb.setCharAt(i, 'a'); sb.insert(i + 1, "Nd_cHaR"); } else if (sb.charAt(i) == '"') { sb.setCharAt(i, 'q'); sb.insert(i + 1, "uote_cHaR"); } i++; } return sb.toString(); }