fix cbz import when no story
[fanfix.git] / src / be / nikiroo / fanfix / supported / Cbz.java
index 062adf0fac71550a8946257f9123e2d178ba7d98..3da65ee728406b0cc21c3e69c425601d700f109e 100644 (file)
@@ -21,7 +21,7 @@ import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.utils.IOUtils;
 import be.nikiroo.utils.Image;
-import be.nikiroo.utils.MarkableFileInputStream;
+import be.nikiroo.utils.streams.MarkableFileInputStream;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -36,11 +36,6 @@ class Cbz extends Epub {
                return url.toString().toLowerCase().endsWith(".cbz");
        }
 
-       @Override
-       public String getSourceName() {
-               return "cbz";
-       }
-
        @Override
        protected String getDataPrefix() {
                return "";
@@ -83,8 +78,7 @@ class Cbz extends Epub {
                InputStream cbzIn = null;
                ZipInputStream zipIn = null;
                try {
-                       cbzIn = new MarkableFileInputStream(new FileInputStream(
-                                       getSourceFileOriginal()));
+                       cbzIn = new MarkableFileInputStream(getSourceFileOriginal());
                        zipIn = new ZipInputStream(cbzIn);
                        for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn
                                        .getNextEntry()) {
@@ -138,25 +132,27 @@ class Cbz extends Epub {
                        story.setChapters(new ArrayList<Chapter>());
 
                        // Check if we can find non-images chapters, for hybrid-cbz support
-                       for (Chapter chap : origStory) {
-                               Boolean isImages = null;
-                               for (Paragraph para : chap) {
-                                       ParagraphType t = para.getType();
-                                       if (isImages == null && !t.isText(true)) {
-                                               isImages = true;
-                                       }
-                                       if (t.isText(false)) {
-                                               String line = para.getContent();
-                                               // Images are saved in text mode as "[image-link]"
-                                               if (!(line.startsWith("[") && line.endsWith("]"))) {
-                                                       isImages = false;
+                       if (origStory != null) {
+                               for (Chapter chap : origStory) {
+                                       Boolean isImages = null;
+                                       for (Paragraph para : chap) {
+                                               ParagraphType t = para.getType();
+                                               if (isImages == null && !t.isText(true)) {
+                                                       isImages = true;
+                                               }
+                                               if (t.isText(false)) {
+                                                       String line = para.getContent();
+                                                       // Images are saved in text mode as "[image-link]"
+                                                       if (!(line.startsWith("[") && line.endsWith("]"))) {
+                                                               isImages = false;
+                                                       }
                                                }
                                        }
-                               }
 
-                               if (isImages != null && !isImages) {
-                                       story.getChapters().add(chap);
-                                       chap.setNumber(story.getChapters().size());
+                                       if (isImages != null && !isImages) {
+                                               story.getChapters().add(chap);
+                                               chap.setNumber(story.getChapters().size());
+                                       }
                                }
                        }