summaryrefslogtreecommitdiffstats
path: root/src/org/madore/android/unicodeMap/UnicodeCharacter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/madore/android/unicodeMap/UnicodeCharacter.java')
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeCharacter.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeCharacter.java b/src/org/madore/android/unicodeMap/UnicodeCharacter.java
index 34bab47..646c696 100644
--- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java
+++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java
@@ -6,6 +6,10 @@ import java.util.Map;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Formatter;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.IOException;
public class UnicodeCharacter implements UnicodeDisplayable {
@@ -320,4 +324,32 @@ public class UnicodeCharacter implements UnicodeDisplayable {
return this.getLabel();
}
+ static byte[] toUtf8(String s) {
+ try {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream(8);
+ OutputStreamWriter writer = new OutputStreamWriter(buf, "UTF-8");
+ writer.write(s, 0, s.length());
+ writer.close();
+ return buf.toByteArray();
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError("UTF-8 encoding unsupported");
+ } catch (IOException e) {
+ throw new AssertionError("this is impossible");
+ }
+ }
+
+ static byte[] toUtf16(String s) {
+ try {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream(8);
+ OutputStreamWriter writer = new OutputStreamWriter(buf, "UTF-16BE");
+ writer.write(s, 0, s.length());
+ writer.close();
+ return buf.toByteArray();
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError("UTF-16BE encoding unsupported");
+ } catch (IOException e) {
+ throw new AssertionError("this is impossible");
+ }
+ }
+
}