public static byte[] toUTF8ByteArray(char[] string) { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try { toUTF8ByteArray(string, bOut); } catch (IOException e) { throw new IllegalStateException("cannot encode string to byte array!"); } return bOut.toByteArray(); }