List of usage examples for java.lang String getBytes
public byte[] getBytes()
From source file:Main.java
public static final String encryptMd5String(String s) { try {/* www . j a va2 s . c o m*/ byte[] btInput = s.getBytes(); MessageDigest mdInst = MessageDigest.getInstance("MD5"); mdInst.update(btInput); byte[] md = mdInst.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < md.length; i++) { int val = ((int) md[i]) & 0xff; if (val < 16) { sb.append("0"); } sb.append(Integer.toHexString(val)); } return sb.toString(); } catch (Exception e) { return null; } }
From source file:Main.java
public static byte[] encrypotByte16(String key) { byte[] tempBytes = new byte[16]; byte keyByte[] = key.getBytes(); for (int i = 0; i < keyByte.length; i++) { tempBytes[i] = keyByte[i];/* ww w . ja v a 2 s . com*/ } return tempBytes; }
From source file:Main.java
static InputStream createInputStream(final String input) { return input == null ? null : new ByteArrayInputStream(input.getBytes()); }
From source file:Main.java
protected static byte[] encodeBase64(String value) { byte[] result = null; byte[] binaryData = value.getBytes(); result = org.apache.commons.codec.binary.Base64.encodeBase64(binaryData); // result = str.bytes.encodeBase64().toString(); return result; }
From source file:Main.java
public static String encryptMD2ToString(String data) { return encryptMD2ToString(data.getBytes()); }
From source file:Main.java
public static void intArrayToFile(Context myContext, String filename, int[] array) { File root = myContext.getFilesDir(); File current = new File(root, filename); current.delete();// www . java2 s. c om FileOutputStream outputStream; try { outputStream = myContext.openFileOutput(filename, Context.MODE_APPEND); for (int i : array) { String s = "" + i; outputStream.write(s.getBytes()); outputStream.write("\n".getBytes()); } outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static File getFileFromBytes(String name, String path) { byte[] b = name.getBytes(); BufferedOutputStream stream = null; File file = null;/*from w w w . ja v a 2 s . c o m*/ try { file = new File(Environment.getExternalStorageDirectory() + path); FileOutputStream fstream = new FileOutputStream(file); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return file; }
From source file:Main.java
public static String encryptSHA1ToString(String data) { return encryptSHA1ToString(data.getBytes()); }
From source file:Main.java
public static String compressString(String value) { String base64String;// w w w . j a v a 2 s . c o m byte[] bytes = value.getBytes(); byte[] base64bytes = Base64.encodeBase64(bytes); base64String = new String(base64bytes); return base64String; }
From source file:Main.java
public static String substring(String str, int toCount, String more) { int reInt = 0; String reStr = ""; if (str == null) return ""; char[] tempChar = str.toCharArray(); for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) { String s1 = String.valueOf(tempChar[kk]); byte[] b = s1.getBytes(); reInt += b.length;//from w w w .ja va 2s . co m reStr += tempChar[kk]; } if (toCount == reInt || (toCount == reInt - 1)) reStr += more; return reStr; }