The list of methods to do Unicode Create are organized into topic(s).
byte[]
getUnicodeByteArray(String str) get Unicode Byte Array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
for (int i = 0; i < str.length(); i++) {
dos.writeChar((int) str.charAt(i));
} catch (Exception e) {
return baos.toByteArray();
byte[]
getUnicodeBytes(String s) Converts the string into a little-endian array of Unicode bytes
try {
byte[] b = s.getBytes(UNICODE_ENCODING);
if (b.length == (s.length() * 2 + 2)) {
byte[] b2 = new byte[b.length - 2];
System.arraycopy(b, 2, b2, 0, b2.length);
b = b2;
return b;
...
String
getUnicodeString(byte[] d, int length, int pos) Gets a string from the data array
try {
byte[] b = new byte[length * 2];
System.arraycopy(d, pos, b, 0, length * 2);
return new String(b, UNICODE_ENCODING);
} catch (UnsupportedEncodingException e) {
return "";
String
getUnicodeText(Object text) get Unicode Text
if (text == null) {
return null;
} else if (text instanceof byte[]) {
return new String((byte[]) text, "UTF-8");
} else {
return String.valueOf(text);
String
toUnicode(final String toUnicode, final boolean toLowerCase) Converts all characters from the given String to unicodes characters encoded like \uxxxx.
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < toUnicode.length(); i++) {
final String hex = Integer.toHexString(toUnicode.codePointAt(i));
if (toLowerCase) {
hex.toLowerCase();
} else {
hex.toUpperCase();
final String hexWithZeros = "0000" + hex;
final String hexCodeWithLeadingZeros = hexWithZeros.substring(hexWithZeros.length() - 4);
sb.append("\\u" + hexCodeWithLeadingZeros);
return sb.toString();
String
toUnicode(String input) to Unicode
StringBuilder ret = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (!Character.isWhitespace(ch) && ch < 0x20 || ch > 0x7e) {
ret.append("\\u");
ret.append(leading4Zeros(Integer.toHexString(ch)));
} else {
ret.append(ch);
...
String
toUnicode(String input) to Unicode
String output = "";
try {
if (input != null && input.length() > 0) {
for (int i = 0; i < input.length(); i++) {
output += toUnicode(input.charAt(i));
} catch (Exception e) {
...
String
toUnicode(String input) to Unicode
StringBuffer ret = new StringBuffer();
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if ((!Character.isWhitespace(ch) && ch < 0x20 || ch > 0x7e)) {
ret.append("\\u");
ret.append(fillChar(Integer.toHexString(ch), '0', 4, true));
} else {
ret.append(ch);
...