List of usage examples for java.lang String getBytes
public byte[] getBytes()
From source file:Main.java
public static InputStream toInputStream(String str) { return new ByteArrayInputStream(str.getBytes()); }
From source file:Main.java
public static String decodeBASE64(String key) throws Exception { byte[] data = Base64.decode(key.getBytes(), Base64.DEFAULT); String str = String.valueOf(data); return str;//from w ww . ja v a2 s . co m }
From source file:Main.java
public static String getNewString(String str) { byte[] data = str.getBytes(); int index = data.length; for (int i = 0; i < data.length; i++) { if (data[i] < 48 || data[i] > 57) { index = i;/*from w w w . ja v a2 s. c o m*/ break; } } byte[] temp = new byte[index]; System.arraycopy(data, 0, temp, 0, index); String res; try { res = new String(temp, "GBK"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } return res; }
From source file:Main.java
public static String utf8Encode(String str) { if (!isEmpty(str) && str.getBytes().length != str.length()) { try {/* w w w.ja v a 2 s . com*/ return URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("UnsupportedEncodingException occurred. ", e); } } return str; }
From source file:Main.java
public static boolean valiChar(String string) { StringTokenizer s = new StringTokenizer(string, ","); // int num=0; if (s.hasMoreTokens()) { String str = s.nextToken(); byte[] cc = str.getBytes(); int a = (int) cc[0]; if (a < 32 || a > 127) { return false; }//from w w w . j ava 2 s . co m } return true; }
From source file:Main.java
public static int getStrLength(String content) { int length = 0; int tempLength = 0; for (int i = 0; i < content.length(); i++) { String temp = content.charAt(i) + ""; if (temp.getBytes().length == 3) { length++;// w ww. j a v a 2 s . c o m } else { tempLength++; } } length += tempLength / 2 + ((tempLength % 2) == 0 ? 0 : 1); return length; }
From source file:Main.java
static byte[] decodeIdentifier(String identifier) { return Base64.decodeBase64(identifier.getBytes()); }
From source file:ch.windmobile.server.social.mongodb.util.AuthenticationServiceUtil.java
public static String createSHA1(String email, byte[] pwd) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA1"); String base = email + ":" + new String(pwd); byte[] result = md.digest(base.getBytes()); return new String(Base64.encode(result)); }
From source file:br.gov.to.secad.aede.util.CriptografiaHash.java
static public String codificar(String valor) { return Base64.encodeBase64String(valor.getBytes()); }
From source file:Main.java
public static boolean allowMaxLenthOfString(String s, int charNum) { int num = 0;//www . ja va2 s . c o m for (int i = 0; i < s.length(); i++) { String tmp = s.substring(i, i + 1); if (tmp.getBytes().length == 3) { num += 2; } else if (tmp.getBytes().length == 1) { num += 1; } } if (num <= charNum) { return true; } return false; }