Fix UTF-8 and "/" -> "\" issues for Win32 fanfix-0.9.5
authorNiki Roo <niki@nikiroo.be>
Fri, 17 Feb 2017 12:46:38 +0000 (13:46 +0100)
committerNiki Roo <niki@nikiroo.be>
Fri, 17 Feb 2017 12:46:38 +0000 (13:46 +0100)
It works on Windows now

VERSION
libs/nikiroo-utils-0.9.8-sources.jar [moved from libs/nikiroo-utils-0.9.7-sources.jar with 71% similarity]
src/be/nikiroo/fanfix/Library.java
src/be/nikiroo/fanfix/output/Cbz.java
src/be/nikiroo/fanfix/output/Epub.java
src/be/nikiroo/fanfix/output/Html.java
src/be/nikiroo/fanfix/output/InfoCover.java
src/be/nikiroo/fanfix/output/LaTeX.java
src/be/nikiroo/fanfix/output/Text.java
src/be/nikiroo/fanfix/reader/LocalReader.java

diff --git a/VERSION b/VERSION
index a602fc9e283389306d606c164ce73ac338999373..b0bb878545dc6dc410a02b0df8b7ea9fd5705960 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.9.4
+0.9.5
similarity index 71%
rename from libs/nikiroo-utils-0.9.7-sources.jar
rename to libs/nikiroo-utils-0.9.8-sources.jar
index dbccbca122182540b78a387abd863fae900e38b2..3f930a41e0498a9cef074ffc2414e2120d788b81 100644 (file)
Binary files a/libs/nikiroo-utils-0.9.7-sources.jar and b/libs/nikiroo-utils-0.9.8-sources.jar differ
index b5f246c6abe8eaa3f9a034da164ee99f290434c8..a8d9302bfe15cc05d87fe11345b11e6e3f3c0284 100644 (file)
@@ -136,7 +136,7 @@ public class Library {
         * @param luid
         *            the Library UID of the story
         * 
-        * @return the corresponding {@link Story}
+        * @return the corresponding {@link Story} or NULL if not found
         */
        public Story getStory(String luid) {
                if (luid != null) {
index f618f59da51a192065ea7cd4aa9d9c141dcbe9e3..2c9dbc3f42df74d1942b0595e1184726b93d6156 100644 (file)
@@ -1,8 +1,10 @@
 package be.nikiroo.fanfix.output;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
@@ -59,7 +61,8 @@ class Cbz extends BasicOutput {
                        }
                }
 
-               FileWriter writer = new FileWriter(new File(dir, "URL"));
+               BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+                               new FileOutputStream(new File(dir, "URL")), "UTF-8"));
                try {
                        if (meta != null) {
                                writer.write(meta.getUuid());
@@ -70,7 +73,8 @@ class Cbz extends BasicOutput {
                        writer.close();
                }
 
-               writer = new FileWriter(new File(dir, "SUMMARY"));
+               writer = new BufferedWriter(new OutputStreamWriter(
+                               new FileOutputStream(new File(dir, "SUMMARY")), "UTF-8"));
                try {
                        String title = "";
                        if (meta != null && meta.getTitle() != null) {
index f27391b4c1e7b6583304bdcb4b05ff45e2ac1850..3e875aa11a036f6a0c72edf87b8ead77cc4db209 100644 (file)
@@ -1,9 +1,11 @@
 package be.nikiroo.fanfix.output;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStreamWriter;
 import java.net.URL;
 
 import javax.imageio.ImageIO;
@@ -14,14 +16,14 @@ import be.nikiroo.fanfix.bundles.StringId;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
-import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.utils.IOUtils;
 import be.nikiroo.utils.StringUtils;
 
 class Epub extends BasicOutput {
        private File tmpDir;
-       private FileWriter writer;
+       private BufferedWriter writer;
        private boolean inDialogue = false;
        private boolean inNormal = false;
        private File images;
@@ -119,7 +121,9 @@ class Epub extends BasicOutput {
        protected void writeChapterHeader(Chapter chap) throws IOException {
                String filename = String.format("%s%03d%s", "chapter-",
                                chap.getNumber(), ".xml");
-               writer = new FileWriter(new File(tmpDir + "/OPS", filename));
+               writer = new BufferedWriter(new OutputStreamWriter(
+                               new FileOutputStream(new File(tmpDir + File.separator + "OPS",
+                                               filename)), "UTF-8"));
                inDialogue = false;
                inNormal = false;
                try {
index fcffec67a2a5403c300b19a5d712f487d2817f6d..3ed52ad6a3b22491397b61aeb31175320dbcdada 100644 (file)
@@ -1,9 +1,11 @@
 package be.nikiroo.fanfix.output;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStreamWriter;
 
 import javax.imageio.ImageIO;
 
@@ -19,7 +21,7 @@ import be.nikiroo.utils.StringUtils;
 
 class Html extends BasicOutput {
        private File dir;
-       protected FileWriter writer;
+       protected BufferedWriter writer;
        private boolean inDialogue = false;
        private boolean inNormal = false;
 
@@ -32,12 +34,12 @@ class Html extends BasicOutput {
                target.mkdir();
                dir = target;
 
-               targetName = new File(targetName, "index").getPath();
                targetName += getDefaultExtension();
 
                target = new File(targetDir, targetName);
 
-               writer = new FileWriter(target);
+               writer = new BufferedWriter(new OutputStreamWriter(
+                               new FileOutputStream(target), "UTF-8"));
                try {
                        super.process(story, targetDir, targetNameOrig);
                } finally {
index 74505e7dd72bc4b290feb801ab7c588166a0280e..1a63dce664d465f4e982fb331861fd574ad695ac 100644 (file)
@@ -1,8 +1,10 @@
 package be.nikiroo.fanfix.output;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 
 import javax.imageio.ImageIO;
 
@@ -14,7 +16,8 @@ class InfoCover {
        public static void writeInfo(File targetDir, String targetName,
                        MetaData meta) throws IOException {
                File info = new File(targetDir, targetName + ".info");
-               FileWriter infoWriter = new FileWriter(info);
+               BufferedWriter infoWriter = new BufferedWriter(new OutputStreamWriter(
+                               new FileOutputStream(info), "UTF-8"));
 
                if (meta != null) {
                        try {
@@ -73,8 +76,8 @@ class InfoCover {
                }
        }
 
-       private static void writeMeta(FileWriter writer, String key, String value)
-                       throws IOException {
+       private static void writeMeta(BufferedWriter writer, String key,
+                       String value) throws IOException {
                if (value == null) {
                        value = "";
                }
index a4ed4d27eaf37592c1eae3aa97a105ed59a96c5e..d322e4a7f3e67fd99ac71b6cf8fa6724fa86f6f6 100644 (file)
@@ -1,19 +1,21 @@
 package be.nikiroo.fanfix.output;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.bundles.StringId;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
 
 class LaTeX extends BasicOutput {
-       protected FileWriter writer;
+       protected BufferedWriter writer;
        private boolean lastWasQuote = false;
 
        // quote chars
@@ -34,7 +36,8 @@ class LaTeX extends BasicOutput {
 
                File target = new File(targetDir, targetName);
 
-               writer = new FileWriter(target);
+               writer = new BufferedWriter(new OutputStreamWriter(
+                               new FileOutputStream(target), "UTF-8"));
                try {
                        super.process(story, targetDir, targetNameOrig);
                } finally {
index 4555ce621f68816ec9271681497476042897b7fc..4acfa762cd82788fcad70707e073983e65b08293 100644 (file)
@@ -1,8 +1,10 @@
 package be.nikiroo.fanfix.output;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.net.URL;
 
 import be.nikiroo.fanfix.Instance;
@@ -10,11 +12,11 @@ import be.nikiroo.fanfix.bundles.StringId;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
-import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
 
 class Text extends BasicOutput {
-       protected FileWriter writer;
+       protected BufferedWriter writer;
        protected File targetDir;
 
        @Override
@@ -27,7 +29,8 @@ class Text extends BasicOutput {
 
                File target = new File(targetDir, targetName);
 
-               writer = new FileWriter(target);
+               writer = new BufferedWriter(new OutputStreamWriter(
+                               new FileOutputStream(target), "UTF-8"));
                try {
                        super.process(story, targetDir, targetNameOrig);
                } finally {
index bfb8b97276d9d71b9d76782b592409e1c02c8c73..86b779c343c0b964d9c80d96493ccd47ec02f7d5 100644 (file)
@@ -48,21 +48,23 @@ class LocalReader extends BasicReader {
        }
 
        // return new luid
-       public String imprt(String luid) {
+       public String imprt(String luid) throws IOException {
                try {
                        Story story = Instance.getLibrary().getStory(luid);
-                       story = lib.save(story);
-                       return story.getMeta().getLuid();
+                       if (story != null) {
+                               story = lib.save(story);
+                               return story.getMeta().getLuid();
+                       } else {
+                               throw new IOException("Cannot find story in Library: " + luid);
+                       }
                } catch (IOException e) {
-                       Instance.syserr(new IOException(
+                       throw new IOException(
                                        "Cannot import story from library to LocalReader library: "
-                                                       + luid, e));
+                                                       + luid, e);
                }
-
-               return null;
        }
 
-       public File getTarget(String luid) {
+       public File getTarget(String luid) throws IOException {
                MetaData meta = lib.getInfo(luid);
                File file = lib.getFile(luid);
                if (file == null) {