List of usage examples for java.lang String getBytes
public byte[] getBytes(Charset charset)
From source file:Main.java
public static boolean isGB2312(char c) { Character ch = Character.valueOf(c); String sCh = ch.toString(); try {//from ww w. java 2 s.co m byte[] bb = sCh.getBytes("gb2312"); if (bb.length > 1) { return true; } } catch (UnsupportedEncodingException ex) { return false; } return false; }
From source file:com.fruit.core.util.MyDigestUtils.java
public static String encode64(String str) { try {//from w ww .ja v a2s . co m return Base64.encodeBase64URLSafeString(str.getBytes("utf-8")); } catch (UnsupportedEncodingException e) { } return Base64.encodeBase64URLSafeString(str.getBytes()); }
From source file:Main.java
public static void writeString(OutputStream os, String s) throws IOException { byte[] b = s.getBytes("UTF-8"); writeLong(os, b.length);//from w ww . j a va 2 s . c o m os.write(b, 0, b.length); }
From source file:Main.java
/** * Convert a string to Ascii bytes./*from w ww. j a v a 2 s . c om*/ * Used for comparing "magic" strings which need to be independent of the default Locale. * * @param inputString * @return the bytes */ public static byte[] toAsciiBytes(String inputString) { try { return inputString.getBytes("ASCII"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // Should never happen } }
From source file:Main.java
public static String decode(String data) throws UnsupportedEncodingException { byte[] b = Base64.decode(data.getBytes(ENCODING), Base64.DEFAULT); return new String(b, ENCODING); }
From source file:Main.java
public static String getBase64String(String value) throws UnsupportedEncodingException { return Base64.encodeToString(value.getBytes("UTF-8"), Base64.NO_WRAP); }
From source file:Main.java
private static InputStream trustedCertificatesInputStreamByCertificateString(String certificate) { try {//from w w w . j ava 2 s . c o m return new ByteArrayInputStream(certificate.getBytes("UTF-8")); } catch (Exception var3) { return null; } }
From source file:Main.java
public static String encryption(String pwd) throws UnsupportedEncodingException { byte[] bytes = pwd.getBytes("utf-8"); for (int i = 0; i < bytes.length; i++) { if (i % 2 == 0) { bytes[i] += 1;//from w w w . j a v a 2 s . c o m } else { bytes[i] -= 1; } } return Base64.encodeToString(bytes, Base64.DEFAULT); }
From source file:Main.java
public static String generateBase64String(String inString) throws UnsupportedEncodingException { byte[] byteTransform = inString.getBytes("UTF-8"); return Base64.encodeToString(byteTransform, Base64.NO_WRAP); }
From source file:Main.java
public static void writeFile(String data, File file) throws IOException { writeFile(data.getBytes(Charset.forName("UTF-8")), file); }