Example usage for java.lang String toCharArray

List of usage examples for java.lang String toCharArray

Introduction

In this page you can find the example usage for java.lang String toCharArray.

Prototype

public char[] toCharArray() 

Source Link

Document

Converts this string to a new character array.

Usage

From source file:com.cloudant.sync.datastore.encryption.DPKEncryptionUtil.java

/**
 * Convert a String to a hex byte array/*  ww w  .  j av  a2s . c  o  m*/
 *
 * @param s The string
 * @return The hex byte array
 */
public static final byte[] hexStringToByteArray(String s) throws DecoderException {
    return Hex.decodeHex(s.toCharArray());
}

From source file:com.zimbra.cs.account.TokenUtil.java

public static Map<?, ?> getAttrs(String data) throws AuthTokenException {
    try {/*w  w  w . ja v  a 2  s.co  m*/
        String decoded = new String(Hex.decodeHex(data.toCharArray()));
        return BlobMetaData.decode(decoded);
    } catch (DecoderException e) {
        throw new AuthTokenException("decoding exception", e);
    } catch (BlobMetaDataEncodingException e) {
        throw new AuthTokenException("blob decoding exception", e);
    }
}

From source file:Main.java

public synchronized static String clean(String string) {
    StringBuilder cleanStr = new StringBuilder();

    Character lookFor = '<';

    for (Character ch : string.toCharArray()) {
        if (ch == lookFor) {
            lookFor = lookFor == '<' ? '>' : '<';
            cleanStr.append(ch);/*from w  w w  . j  a  v a2s  . c  o  m*/
        } else if (lookFor == '>') {
            cleanStr.append(ch);
        }
    }

    return cleanStr.toString();
}

From source file:Main.java

/**
 * Escapes specified string (that is, <tt>'&lt;'</tt> is replaced by "<tt>&amp;#60</tt>;",
 * <tt>'&amp;'</tt> is replaced by "<tt>&amp;#38;</tt>", etc).
 * /*from  w  w  w.  jav  a2  s  . c o m*/
 * @param string string to be escaped
 * @param escaped buffer used to store escaped string (characters are
 *        appended to this buffer)
 */
public static final void escapeXML(String string, StringBuffer escaped) {
    char[] chars = string.toCharArray();
    escapeXML(chars, 0, chars.length, escaped);
}

From source file:Main.java

public static boolean checkFileName(String sInput) {
    boolean checkedValue = true;
    // sInput = sInput.toUpperCase();
    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' && cInput[i] != 'g'
                && cInput[i] != 'h' && cInput[i] != 'i' && cInput[i] != 'j' && cInput[i] != 'k'
                && cInput[i] != 'l' && cInput[i] != 'm' && cInput[i] != 'n' && cInput[i] != 'o'
                && cInput[i] != 'p' && cInput[i] != 'q' && cInput[i] != 'r' && cInput[i] != 's'
                && cInput[i] != 't' && cInput[i] != 'u' && cInput[i] != 'v' && cInput[i] != 'w'
                && cInput[i] != 'x' && cInput[i] != 'y' && cInput[i] != 'z' && cInput[i] != 'A'
                && cInput[i] != 'B' && cInput[i] != 'C' && cInput[i] != 'D' && cInput[i] != 'E'
                && cInput[i] != 'F' && cInput[i] != 'G' && cInput[i] != 'H' && cInput[i] != 'I'
                && cInput[i] != 'J' && cInput[i] != 'K' && cInput[i] != 'L' && cInput[i] != 'M'
                && cInput[i] != 'N' && cInput[i] != 'O' && cInput[i] != 'P' && cInput[i] != 'Q'
                && cInput[i] != 'R' && cInput[i] != 'S' && cInput[i] != 'T' && cInput[i] != 'U'
                && cInput[i] != 'V' && cInput[i] != 'W' && cInput[i] != 'X' && cInput[i] != 'Y'
                && cInput[i] != 'Z' && cInput[i] != '.' && cInput[i] != '_') {
            checkedValue = false;//from   w  w  w . jav a  2s  . co m
        }
    }
    return checkedValue;
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.builder.AbstractBuilder.java

public static StaticBuffer decodeKey(String name) {
    try {/*w  w  w .  j ava2  s .c  o  m*/
        return new StaticArrayBuffer(Hex.decodeHex(name.toCharArray()));
    } catch (DecoderException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.rdonasco.security.utils.EncryptionUtil.java

public static String encryptWithPassword(String stringToEncrypt, String password) throws Exception {
    PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), SALT, COUNT);
    SecretKey pbeKey = getKeyFactory().generateSecret(pbeKeySpec);
    Cipher pbeCipher = Cipher.getInstance(CIPHER_KEY_SPEC);
    pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, PBE_PARAM_SPEC);
    byte[] encryptedBytes = pbeCipher.doFinal(stringToEncrypt.getBytes());
    return Base64.encodeBase64String(encryptedBytes);
}

From source file:com.rdonasco.security.utils.EncryptionUtil.java

public static String decryptWithPassword(String encryptedString, String password) throws Exception {
    PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), SALT, COUNT);
    SecretKey pbeKey = getKeyFactory().generateSecret(pbeKeySpec);
    Cipher pbeCipher = Cipher.getInstance(CIPHER_KEY_SPEC);
    pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, PBE_PARAM_SPEC);
    byte[] decryptedBytes = pbeCipher.doFinal(Base64.decodeBase64(encryptedString));
    return new String(decryptedBytes);
}

From source file:Main.java

static String[] tokenize(String listString, String delimiters) {
    char[] delimiterChars = delimiters.toCharArray();

    char[] listChars = listString.toCharArray();
    int i = 0;//from  w w w  .  j  a  va  2s .c  om

    List<String> stringList = new LinkedList<String>();

    StringBuffer buffer = new StringBuffer();
    while (i < listChars.length) {

        char c = listChars[i];

        boolean advance = false;
        for (char d : delimiterChars) {
            if (c == d) {
                stringList.add(buffer.toString());
                buffer = new StringBuffer();
                advance = true;
                break;
            }
        }

        if (!advance) {
            if (c == '\\') {
                if (i < listChars.length - 1) {
                    char next = listChars[i + 1];

                    //if one of next chars is delimiter chars, 
                    //then advance to next char
                    for (char d : delimiterChars) {
                        if (d == next) {
                            i++;
                            c = next;
                            break;
                        }
                    }
                }
            }

            buffer.append(c);
        }

        i++;
    }

    //add last buffer to String
    stringList.add(buffer.toString());

    String[] pairings = stringList.toArray(EMPTY_STRING);
    //StringUtils.tokenizeToStringArray(listString, delimiters);
    return pairings;
}

From source file:Main.java

private static String capitalizedName(final String property) {
    if (null == property || property.length() < 1)
        return property;

    final char[] chars = property.toCharArray();
    chars[0] = Character.toUpperCase(chars[0]);
    return new String(chars);
}