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:mitm.common.util.HexUtils.java

public static byte[] hexDecode(String hex, byte[] defaultIfNull) throws DecoderException {
    if (hex == null) {
        return defaultIfNull;
    }/*from   ww  w  . ja  va2  s  . c o m*/

    return Hex.decodeHex(hex.toCharArray());
}

From source file:com.cedarsoft.crypt.Hash.java

/**
 * Creates a hash from the given hex value
 *
 * @param algorithm  the algorithm/*from   w w w .j a  va 2s.  co m*/
 * @param valueAsHex the hex value
 * @return the hash
 */
@Nonnull
public static Hash fromHex(@Nonnull Algorithm algorithm, @Nonnull String valueAsHex) {
    try {
        return new Hash(algorithm, Hex.decodeHex(valueAsHex.toCharArray()));
    } catch (DecoderException e) {
        throw new IllegalArgumentException("Invalid hex string <" + valueAsHex + ">", e);
    }
}

From source file:com.nortal.petit.beanmapper.BeanMappingStringUtils.java

/**
 * Transforms the given camel case string into it's underscore
 * representation. Example: someString -&gt; some_string.
 * /*from   w  ww.jav a  2s  . c o m*/
 * @param camelCase
 *            string in camel case.
 * @return string in underscore representation.
 */
public static String camelCaseToUnderscore(String camelCase) {
    if (StringUtils.isBlank(camelCase)) {
        return camelCase;
    }

    StringBuilder sb = new StringBuilder();

    for (Character c : camelCase.toCharArray()) {
        if (Character.isUpperCase(c)) {
            c = Character.toLowerCase(c);
            if (sb.length() > 0) {
                sb.append("_");
            }
        }

        sb.append(c);
    }

    return sb.toString();
}

From source file:game.utils.Utils.java

public static int count(String s, char c) {
    int count = 0;
    for (char curr : s.toCharArray())
        if (curr == c)
            count++;/*w ww. j av a  2  s  .c  om*/
    return count;
}

From source file:Main.java

public static String replaceMatch(String line, String oldString, String newString) {
    int i = 0;//from  w  w w. j  a  va2  s. c o m
    int j = 0;
    if ((i = line.indexOf(oldString, i)) >= 0) {
        char line2[] = line.toCharArray();
        char newString2[] = newString.toCharArray();
        int oLength = oldString.length();
        StringBuffer buffer = new StringBuffer(line2.length);
        buffer.append(line2, 0, i).append(newString2);
        i += oLength;
        for (j = i; (i = line.indexOf(oldString, i)) > 0; j = i) {
            buffer.append(line2, j, i - j).append(newString2);
            i += oLength;
        }
        buffer.append(line2, j, line2.length - j);
        return buffer.toString();
    } else {
        return line;
    }
}

From source file:Main.java

/**
 * Escapes invalid XML characters in the given character data using XML entities. For the
 * moment, only the following characters are being escaped: (<), (&), (') and (").
 * // www.j a v a2s .  c om
 * Remark: we don't escape the (>) character to keep the readability of the configuration
 * mapping! The XML spec only requires that the (&) and (<) characters are being escaped inside
 * character data.
 * 
 * @param text
 *            the character data to escape
 * @return the escaped character data
 */
public static String escape(String text) {
    if (text == null) {
        return null;
    }

    StringBuffer result = new StringBuffer(text.length());

    char[] chars = text.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        switch (chars[i]) {
        case '&':
            result.append("&amp;");
            break;
        case '<':
            result.append("&lt;");
            break;
        case '\'':
            result.append("&apos;");
            break;
        case '\"':
            result.append("&quot;");
            break;
        default:
            result.append(chars[i]);
        }
    }

    return result.toString();
}

From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.TierUtil.java

private static ChatColor findColor(final String s) {
    char[] c = s.toCharArray();
    for (int i = 0; i < c.length; i++) {
        if (c[i] == (char) 167 && (i + 1) < c.length) {
            return ChatColor.getByChar(c[i + 1]);
        }//from   ww  w . jav  a2s.c  om
    }
    return null;
}

From source file:com.bitctrl.net.MAC.java

/**
 * Bestimmt aus einem String die MAC-Adresse. Der String muss im Format
 * {@code x:x:x:x:x:x} vorliegen.//from   w ww . ja  v  a 2 s.  c  o  m
 * 
 * @param address
 *            die Adresse als Zeichenkette
 * @return die Adresse
 * @throws IllegalArgumentException
 *             die bergebene Zeichenkette konnte nicht interpretiert werden
 */
public static MAC valueOf(final String address) throws IllegalArgumentException {
    if (address == null || address.length() == 0) {
        return null;
    }

    final String hex = address.replace(":", "");
    try {
        final byte[] data = Hex.decodeHex(hex.toCharArray());
        if (data.length != 6) {
            throw new IllegalArgumentException("Can not determine MAC address.");
        }
        return new MAC(data);
    } catch (final DecoderException ex) {
        throw new IllegalArgumentException("Can not determine MAC address.", ex);
    }
}

From source file:com.google.nigori.common.DSATest.java

private static byte[] fromHex(String data) {
    try {// ww w .ja  va  2 s  .com
        return Hex.decodeHex(data.toCharArray());
    } catch (DecoderException e) {
        throw new RuntimeException(e);
    }
}

From source file:models.logic.CipherDecipher.java

public static SecretKey fileToKey(String keyPath) throws IOException, DecoderException {
    File keyFile = new File(keyPath);
    String data = new String(readFileToByteArray(keyFile));
    byte[] encoded;
    try {//w w  w. ja v a  2  s .c  o m
        encoded = decodeHex(data.toCharArray());
    } catch (DecoderException e) {
        e.printStackTrace();
        return null;
    }
    return new SecretKeySpec(encoded, "AES");
}