List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:com.lll.util.EncodeUtils.java
/** * Hex?./*w w w. j a va 2 s. com*/ */ public static byte[] hexDecode(String input) { try { return Hex.decodeHex(input.toCharArray()); } catch (DecoderException e) { throw new IllegalStateException("Hex Decoder exception", e); } }
From source file:com.yilang.commons.utils.util.Encodes.java
public static byte[] decodeHex(String input) { try {/*from w w w .j av a 2 s .c o m*/ return Hex.decodeHex(input.toCharArray()); } catch (DecoderException e) { throw Exceptions.unchecked(e); } }
From source file:Main.java
/** * get a fixed-length random string, its a mixture of chars in source * * @param source//from w w w.j av a 2 s . c om * @param length * @return <ul> * <li>if source is null or empty, return null</li> * <li>else see {@link RandomUtil#getRandom(char[] sourceChar, int length)}</li> * </ul> */ public static String getRandom(String source, int length) { return source == null ? null : getRandom(source.toCharArray(), length); }
From source file:Main.java
public static final boolean isURLEncoded(String str) { if (str == null || "".equals(str)) { return false; }/*from w ww . j av a 2s .c o m*/ char[] chars = str.toCharArray(); boolean containsPercent = false; for (char c : chars) { if (Character.isWhitespace(c)) { return false; } if (!dontNeedEncoding.get(c)) { return false; } if (c == '%') { containsPercent = true; } } if (!containsPercent) { return false; } return true; }
From source file:Main.java
/** * XML comment does not support some characters inside its content but there is no official escaping/unescaping for * it so we made our own./*from w ww. j av a 2 s.c o m*/ * * @param content the XML comment content to unescape * @return the unescaped content. * @see #escapeXMLComment(String) * @since 1.9M2 */ public static String unescapeXMLComment(String content) { StringBuffer str = new StringBuffer(content.length()); char[] buff = content.toCharArray(); boolean escaped = false; for (char c : buff) { if (!escaped && c == '\\') { escaped = true; continue; } str.append(c); escaped = false; } return str.toString(); }
From source file:Main.java
/** * Encodes the given string so that it conforms to the XML 1.0 specification * for CDATA and TEXT nodes.// w w w . j ava 2 s . c o m * * @param toEncode The string to encode * * @return the encoded string */ public static String encodeText(String toEncode) { StringBuffer buffer = new StringBuffer(); char[] cs = toEncode.toCharArray(); for (int i = 0; i < cs.length; i++) { switch (cs[i]) { case '&': buffer.append("&"); break; case '<': buffer.append("<"); break; case '>': buffer.append(">"); break; default: buffer.append(cs[i]); } } return buffer.toString(); }
From source file:com.cloudant.sync.datastore.encryption.EncryptionTestConstants.java
private static byte[] hexStringToByteArray(String s) { try {// ww w. j a va2 s. c o m return Hex.decodeHex(s.toCharArray()); } catch (DecoderException ex) { // Crash the tests at this point, we've input bad data in our hard-coded values throw new RuntimeException("Error decoding hex data: " + s); } }
From source file:Main.java
public static String castHexKeyboard(String sInput) { String sOutput = ""; sInput = sInput.toUpperCase();/* w w w .ja v a 2s . c om*/ char[] cInput = sInput.toCharArray(); for (int i = 0; i < sInput.length(); i++) { if (cInput[i] != '0' && cInput[i] != '1' && cInput[i] != '2' && cInput[i] != '3' && cInput[i] != '4' && cInput[i] != '5' && cInput[i] != '6' && cInput[i] != '7' && cInput[i] != '8' && cInput[i] != '9' && cInput[i] != 'A' && cInput[i] != 'B' && cInput[i] != 'C' && cInput[i] != 'D' && cInput[i] != 'E') { cInput[i] = 'F'; } sOutput += cInput[i]; } return sOutput; }
From source file:Main.java
public static byte[] getBytes(String in) { byte[] result = new byte[in.length() * 2]; int output = 0; for (char ch : in.toCharArray()) { result[output++] = (byte) (ch & 0xFF); result[output++] = (byte) (ch >> 8); }//from w w w . j av a 2 s. co m return result; }
From source file:Main.java
/** * Returns the number of occurrences of needle in haystack. * //from w ww. j a va 2 s. co m * @param haystack string to search through * @param needle character to find * @return number of occurences of needle in haystack * * @version 0.2 * @since 0.2 */ public static int countOccurrences(String haystack, char needle) { int iCount = 0; for (char c : haystack.toCharArray()) { if (c == needle) { iCount++; } } return iCount; }