Fix UTF8 bug, create first executable JAR file v1.0-beta1
authorNiki Roo <niki@nikiroo.be>
Thu, 3 Mar 2016 10:13:17 +0000 (11:13 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 3 Mar 2016 10:13:17 +0000 (11:13 +0100)
jvcard-1.0-beta1.jar [new file with mode: 0644]
src/be/nikiroo/jvcard/tui/Main.java

diff --git a/jvcard-1.0-beta1.jar b/jvcard-1.0-beta1.jar
new file mode 100644 (file)
index 0000000..38abb59
Binary files /dev/null and b/jvcard-1.0-beta1.jar differ
index a0357bec89e4c0a59ee19899d0d8bbb32cd9723d..eda0c69407059a7a200fa4e43d6dce2186eeae4e 100644 (file)
@@ -2,6 +2,8 @@ package be.nikiroo.jvcard.tui;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -32,7 +34,7 @@ import com.googlecode.lanterna.terminal.Terminal;
  */
 public class Main {
        public static final String APPLICATION_TITLE = "jVcard";
-       public static final String APPLICATION_VERSION = "1.0-beta1-dev";
+       public static final String APPLICATION_VERSION = "1.0-beta2-dev";
 
        static private Trans transService;
 
@@ -45,7 +47,6 @@ public class Main {
         * @return the translation
         */
        static public String trans(StringId id) {
-
                if (transService == null)
                        return "";
 
@@ -119,6 +120,10 @@ public class Main {
                        }
                }
 
+               if (UiColors.getInstance().isUnicode()) {
+                       utf8();
+               }
+
                if (files.size() == 0) {
                        if (filesTried) {
                                System.exit(1);
@@ -167,6 +172,20 @@ public class Main {
                return files;
        }
 
+       /**
+        * Really, really ask for UTF-8 encoding.
+        */
+       static private void utf8() {
+               try {
+                       System.setProperty("file.encoding", "UTF-8");
+                       Field charset = Charset.class.getDeclaredField("defaultCharset");
+                       charset.setAccessible(true);
+                       charset.set(null, null);
+               } catch (SecurityException | NoSuchFieldException
+                               | IllegalArgumentException | IllegalAccessException e) {
+               }
+       }
+
        static private void fullTestTable() throws IOException {
                final Table<String> table = new Table<String>("Column 1", "Column 2",
                                "Column 3");