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.adeptj.modules.security.core.credential.UsernamePasswordCredential.java

public static UsernamePasswordCredential from(String username, String password) {
    return new UsernamePasswordCredential(username, password.toCharArray());
}

From source file:com.jwt.security.auth.cryptographics.Crypto.java

public static byte[] hex(String str) {
    try {//w  ww  . ja v  a  2s.  co m
        return Hex.decodeHex(str.toCharArray());
    } catch (DecoderException e) {
        throw new IllegalStateException(e);
    }
}

From source file:de.petendi.ethereum.secure.proxy.controller.WelcomeController.java

private static String insertLinebreaks(String s, int charsPerLine) {
    char[] chars = s.toCharArray();
    int lastLinebreak = 0;
    boolean wantLinebreak = false;
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < chars.length; i++) {
        if (wantLinebreak && chars[i] == ' ') {
            sb.append("<br/><br/>");
            lastLinebreak = i;//from   ww w. ja  va 2  s  .  co m
            wantLinebreak = false;
        } else {
            sb.append(chars[i]);
        }
        if (i - lastLinebreak + 1 == charsPerLine)
            wantLinebreak = true;
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Encodes an XML element name.//w w w  .  java2s . c o  m
 *
 * <p>This function is mainly for encode element names in result of Drill
 * Through execute, because its element names come from database, we cannot
 * make sure they are valid XML contents.
 *
 * <p>Quoth the <a href="http://xmla.org">XML/A specification</a>, version
 * 1.1:
 * <blockquote>
 * XML does not allow certain characters as element and attribute names.
 * XML for Analysis supports encoding as defined by SQL Server 2000 to
 * address this XML constraint. For column names that contain invalid XML
 * name characters (according to the XML 1.0 specification), the nonvalid
 * Unicode characters are encoded using the corresponding hexadecimal
 * values. These are escaped as _x<i>HHHH_</i> where <i>HHHH</i> stands for
 * the four-digit hexadecimal UCS-2 code for the character in
 * most-significant bit first order. For example, the name "Order Details"
 * is encoded as Order_<i>x0020</i>_Details, where the space character is
 * replaced by the corresponding hexadecimal code.
 * </blockquote>
 *
 * @param name Name of XML element
 * @return encoded name
 */
private static String encodeElementName(String name) {
    StringBuilder buf = new StringBuilder();
    char[] nameChars = name.toCharArray();
    for (char ch : nameChars) {
        String encodedStr = (ch >= CHAR_TABLE.length ? null : CHAR_TABLE[ch]);
        if (encodedStr == null) {
            buf.append(ch);
        } else {
            buf.append(encodedStr);
        }
    }
    return buf.toString();
}

From source file:Main.java

/**
 * Encodes the given string so that it conforms to the XML 1.0 specification
 * for attribute values./*from   w  w  w. ja v  a2 s.c  o m*/
 * 
 * @param toEncode The string to encode
 * 
 * @return the encoded string
 */
public static String encodeAttribute(String toEncode) {
    StringBuffer buffer = new StringBuffer();
    char[] cs = toEncode.toCharArray();

    for (int i = 0; i < cs.length; i++) {
        switch (cs[i]) {
        case '\'':
            buffer.append("&apos;");

            break;

        case '"':
            buffer.append("&quot;");

            break;

        case '&':
            buffer.append("&amp;");

            break;

        case '<':
            buffer.append("&lt;");

            break;

        case '>':
            buffer.append("&gt;");

            break;

        default:
            buffer.append(cs[i]);
        }
    }

    return buffer.toString();
}

From source file:com.aestasit.markdown.Markdown.java

public static RootNode toAst(final String text, final int options) throws IOException {
    return toAst(text.toCharArray(), options);
}

From source file:io.lavagna.model.util.ShortNameGenerator.java

private static String takeFirstFourUpperCaseChars(String s) {
    StringBuilder sb = new StringBuilder();
    for (char c : s.toCharArray()) {
        if (Character.isUpperCase(c)) {
            sb.append(c);/*from   w w w . j  a v  a 2  s.  co  m*/
        }
    }
    return sb.substring(0, Math.min(sb.length(), 4));
}

From source file:com.spectralogic.ds3client.utils.hashing.Md5Hash.java

public static Md5Hash fromHexString(final String hex) throws InvalidMd5Exception {
    try {/*from   ww  w . j  a v a2s. com*/
        return new Md5Hash(Hex.decodeHex(hex.toCharArray()));
    } catch (final DecoderException e) {
        throw new InvalidMd5Exception(e);
    }
}

From source file:com.integrareti.integraframework.util.RequestUtil.java

/**
 * Returns HTML encoded version of the specified String s.
 * //from  w ww  . jav  a 2  s.com
 * @param s
 *            String to be HTML encoded
 * @return HTML encoded String
 */
public static String htmlEncode(String s) {
    StringBuffer encodedString = new StringBuffer("");
    char[] chars = s.toCharArray();
    for (char c : chars) {
        if (c == '<') {
            encodedString.append("&lt;");
        } else if (c == '>') {
            encodedString.append("&gt;");
        } else {
            encodedString.append(c);
        }
    }
    return encodedString.toString();
}

From source file:com.bjwg.back.util.EncodeUtils.java

public static byte[] decodeHex(String input) {
    try {//ww w.j a  va2  s  .  c om
        return Hex.decodeHex(input.toCharArray());
    } catch (DecoderException e) {
        throw new IllegalStateException("Hex Decoder exception", e);
    }
}