Example usage for java.lang String getBytes

List of usage examples for java.lang String getBytes

Introduction

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

Prototype

public byte[] getBytes(Charset charset) 

Source Link

Document

Encodes this String into a sequence of bytes using the given java.nio.charset.Charset charset , storing the result into a new byte array.

Usage

From source file:Main.java

public static Node parseString(String string) throws Exception {
    InputStream is = new ByteArrayInputStream(string.getBytes("UTF-16"));

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    // from AIMLProcessor.evalTemplate and AIMLProcessor.validTemplate:
    //   dbFactory.setIgnoringComments(true); // fix this
    Document doc = dBuilder.parse(is);
    doc.getDocumentElement().normalize();
    Node root = doc.getDocumentElement();
    return root;/*ww  w  .ja va  2 s . com*/
}

From source file:com.amazonaws.eclipse.core.accounts.preferences.PreferenceValueEncodingUtil.java

public static String decodeString(String s) {
    try {/*from   ww w. ja  v a2 s  . co m*/
        return new String(Base64.decodeBase64(s.getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Failed to decode the String", e);
    }
}

From source file:com.amazonaws.eclipse.core.accounts.preferences.PreferenceValueEncodingUtil.java

public static String encodeString(String s) {
    try {//from w w  w . j  ava  2 s.c  o  m
        return new String(Base64.encodeBase64(s.getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Failed to encode the String", e);
    }
}

From source file:Main.java

public static ByteBuffer getDataBuffer() {
    String lineSeparator = System.getProperty("line.separator");

    StringBuilder sb = new StringBuilder();
    sb.append("test");
    sb.append(lineSeparator);//from w  w w  .  j a  v a 2  s.  c o m

    String str = sb.toString();
    Charset cs = Charset.forName("UTF-8");
    ByteBuffer bb = ByteBuffer.wrap(str.getBytes(cs));

    return bb;
}

From source file:Main.java

public static String encodeBase64(String str) throws UnsupportedEncodingException, Base64DataException {
    return Base64.encodeToString(str.getBytes("UTF-8"), Base64.DEFAULT).replace("\n", "");
}

From source file:Main.java

public static byte[] getBytes(String data, String charsetName) {
    Charset charset = Charset.forName(charsetName);
    return data.getBytes(charset);
}

From source file:Main.java

public static String md5(String string) {
    byte[] hash = null;
    try {//from  ww  w  . j  a  va2  s.  com
        hash = string.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Huh,UTF-8 should be supported?", e);
    }
    return computeMD5(hash);
}

From source file:Main.java

public static String md5(String string) {
    byte[] hash = null;
    try {/*  w w  w .  jav  a 2s .  c o  m*/
        hash = string.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("UTF-8 is not supported", e);
    }
    return computeMD5(hash);
}