List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:com.wondersgroup.api.framework.utils.Encodes.java
/** * Hex?.//from w w w .j av a2s . c o m */ public static byte[] decodeHex(String input) { try { return Hex.decodeHex(input.toCharArray()); } catch (DecoderException e) { // throw new Exception(); return null; } }
From source file:com.idea.quickstart.common.security.Encodes.java
/** * Hex?.// w w w. j a va 2 s . c o m */ public static byte[] decodeHex(String input) { try { return Hex.decodeHex(input.toCharArray()); } catch (DecoderException e) { //ignore } return null; }
From source file:Main.java
/** * Escapes a string with the appropriated XML codes. * @param s the string to be escaped//from w ww . j av a 2s .c o m * @param onlyASCII codes above 127 will always be escaped with &#nn; if <CODE>true</CODE> * @return the escaped string * @since 5.0.6 */ public static String escapeXML(final String s, final boolean onlyASCII) { char cc[] = s.toCharArray(); int len = cc.length; StringBuffer sb = new StringBuffer(); for (int k = 0; k < len; ++k) { int c = cc[k]; switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '"': sb.append("""); break; case '\'': sb.append("'"); break; default: if (isValidCharacterValue(c)) { if (onlyASCII && c > 127) sb.append("&#").append(c).append(';'); else sb.append((char) c); } } } return sb.toString(); }
From source file:Main.java
public static SpannableString getSmallCapsString(String input) { // values needed to record start/end points of blocks of lowercase letters char[] chars = input.toCharArray(); int currentBlock = 0; int[] blockStarts = new int[chars.length]; int[] blockEnds = new int[chars.length]; boolean blockOpen = false; // record where blocks of lowercase letters start/end for (int i = 0; i < chars.length; ++i) { char c = chars[i]; if (c >= 'a' && c <= 'z') { if (!blockOpen) { blockOpen = true;/* w w w. java 2s.c om*/ blockStarts[currentBlock] = i; } // replace with uppercase letters chars[i] = (char) (c - 'a' + '\u0041'); } else { if (blockOpen) { blockOpen = false; blockEnds[currentBlock] = i; ++currentBlock; } } } // add the string end, in case the last character is a lowercase letter blockEnds[currentBlock] = chars.length; // shrink the blocks found above SpannableString output = new SpannableString(String.valueOf(chars)); for (int i = 0; i < Math.min(blockStarts.length, blockEnds.length); ++i) { output.setSpan(new RelativeSizeSpan(0.8f), blockStarts[i], blockEnds[i], Spannable.SPAN_EXCLUSIVE_INCLUSIVE); } return output; }
From source file:com.qatickets.common.StringHelper.java
public static String leaveOnlyLettersAndDigits(String value) { StringBuilder sb = new StringBuilder(); if (StringUtils.isNotBlank(value)) { char[] chars = value.toCharArray(); for (char ch : chars) { if (Character.isLetterOrDigit(ch)) { sb.append(ch);//from www.j a v a 2 s.co m } } } return sb.toString(); }
From source file:XmlUtil.java
/** * Apply some indentiation to some XML. This method is not very * sophisticated and will not cope well with anything but the simplest XML * (no CDATA etc). The algorithm used does not look at element names and * does not actually parse the XML. It also assumes that the forward slash * and greater-than at the end of a self-terminating tag and not seperated * by ant whitespace./* w ww. j a v a 2s . c o m*/ * * @param xmlString * input XML fragment * @return indented XML fragment */ public static String indentXmlSimple(String xmlString) { ByteArrayOutputStream os = new ByteArrayOutputStream(); int indent = 0; char bytes[] = xmlString.toCharArray(); int i = 0; while (i < bytes.length) { if (bytes[i] == '<' && bytes[i + 1] == '/') { os.write('\n'); writeIndentation(os, --indent); } else if (bytes[i] == '<') { if (i > 0) { os.write('\n'); } writeIndentation(os, indent++); } else if (bytes[i] == '/' && bytes[i + 1] == '>') { indent--; } else if (bytes[i] == '>') { } os.write(bytes[i++]); } return os.toString(); }
From source file:com.beligum.core.accounts.UserManager.java
private static String hash(String password, String salt) { KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 2048, 160); try {//from w ww . j a v a2 s .co m SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); byte[] hash = f.generateSecret(spec).getEncoded(); return new String(Hex.encodeHex(hash)); } catch (Exception e) { return null; } }
From source file:Escape.java
/** * Do the escaping./*from w w w .j a v a2 s . co m*/ * * @param st * @return The escaped text. */ public static final String getText(String st) { StringBuffer buff = new StringBuffer(); char[] block = st.toCharArray(); String stEntity = null; int i, last; for (i = 0, last = 0; i < block.length; i++) { switch (block[i]) { case '<': stEntity = "<"; break; case '>': stEntity = ">"; break; case '&': stEntity = "&"; break; case '"': stEntity = """; break; case '\n': stEntity = LINE_SEPARATOR; break; default: /* no-op */ break; } if (stEntity != null) { buff.append(block, last, i - last); buff.append(stEntity); stEntity = null; last = i + 1; } } if (last < block.length) { buff.append(block, last, i - last); } return buff.toString(); }
From source file:Main.java
/** * @param s str/*ww w . ja v a2s . c om*/ * @return String */ public static String fullWidthToHalfWidth(String s) { if (isEmpty(s)) { return s; } char[] source = s.toCharArray(); for (int i = 0; i < source.length; i++) { if (source[i] == 12288) { source[i] = ' '; // } else if (source[i] == 12290) { // source[i] = '.'; } else if (source[i] >= 65281 && source[i] <= 65374) { source[i] = (char) (source[i] - 65248); } else { source[i] = source[i]; } } return new String(source); }
From source file:gobblin.kafka.serialize.MD5Digest.java
/** * Static method to get an MD5Digest from a human-readable string representation * @param md5String//from ww w. j a v a2 s.c o m * @return a filled out MD5Digest */ public static MD5Digest fromString(String md5String) { byte[] bytes; try { bytes = Hex.decodeHex(md5String.toCharArray()); return new MD5Digest(md5String, bytes); } catch (DecoderException e) { throw new IllegalArgumentException("Unable to convert md5string", e); } }