List of usage examples for java.lang String getBytes
public byte[] getBytes(Charset charset)
From source file:Main.java
private static int gbValue(char paramChar) { String str = new String() + paramChar; try {/*ww w . j a va 2s . c o m*/ byte[] arrayOfByte = str.getBytes("GB2312"); if (arrayOfByte.length < 2) return 0; int i = 0xFF00 & arrayOfByte[0] << 8; int j = arrayOfByte[1]; return i + (j & 0xFF); } catch (Exception localException) { } return 0; }
From source file:Main.java
/** * @param text/*from www. j a v a2 s . com*/ * @return */ public static String convert2UTF8(String text) { try { byte[] utf8Bytes = text.getBytes("UTF-8"); text = new String(utf8Bytes, "UTF-8"); } catch (java.io.UnsupportedEncodingException e) { e.printStackTrace(); } return text; }
From source file:Main.java
private static int gbValue(char ch) { String str = new String(); str += ch;//w ww . ja v a 2s. c o m try { byte[] bytes = str.getBytes("GBK"); if (bytes.length < 2) return 0; return (bytes[0] << 8 & 0xff00) + (bytes[1] & 0xff); } catch (Exception e) { return 0; } }
From source file:io.viewserver.core.Utils.java
public static String serialise(String value) { return new String(Base64.getEncoder().encode(getBytes(value.getBytes(Charsets.UTF_8))), Charsets.UTF_8); }
From source file:net.cpollet.whereareyou.Base64Utils.java
public static byte[] toBytes(String string) { try {/*from w w w. ja v a 2s . c om*/ return Base64.decodeBase64(string.getBytes("UTF-8")); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static InputStream streamify(String xml) { return new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); }
From source file:Main.java
public static String makeMD5Hash(String text) { try {/* www . ja v a 2 s . c om*/ return makeMD5Hash(text.getBytes("utf-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static int getTextLength(String str) { int length = 0; try {/*from w ww .j av a2 s . co m*/ str = new String(str.getBytes("GBK"), "ISO8859_1"); length = str.length(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return length; }
From source file:Main.java
public static String makeSHA1Hash(String text) { try {/*from www.j a v a 2 s . com*/ return makeSHA1Hash(text.getBytes("utf-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * function encrypt the string and return the result * @param stringToEncrypt the string against which the encryption to be performed * @return the encrypted String/* ww w. j av a2s.co m*/ */ public static final String encrypt(String stringToEncrypt) { try { byte[] data = stringToEncrypt.getBytes("UTF-8"); String base64 = Base64.encodeToString(data, Base64.DEFAULT); return base64; } catch (Exception e) { e.printStackTrace(); } return stringToEncrypt; // try { // Key aesKey = new SecretKeySpec(key.getBytes(), "AES"); // Cipher cipher = Cipher.getInstance("AES"); // cipher.init(Cipher.ENCRYPT_MODE, aesKey); // byte[] encrypted = cipher.doFinal(stringToEncrypt.getBytes()); // return new String(encrypted); // }catch (Exception e){ // // } // return null; }