Added utility methods for converting string to UTF-8 and vice versa.

This commit is contained in:
akwizgran
2014-02-07 22:00:51 +00:00
parent 0626fe6c7c
commit f6360c09d4
2 changed files with 10 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
package org.briarproject.util;
import java.nio.charset.Charset;
public class StringUtils {
private static final char[] HEX = new char[] {
@@ -11,6 +13,14 @@ public class StringUtils {
return s == null || s.length() == 0;
}
public static byte[] toUtf8(String s) {
return s.getBytes(Charset.forName("UTF-8"));
}
public static String fromUtf8(byte[] bytes) {
return new String(bytes, Charset.forName("UTF-8"));
}
/** Converts the given byte array to a hex character array. */
public static char[] toHexChars(byte[] bytes) {
char[] hex = new char[bytes.length * 2];