1 package org.readium.r2_streamer.parser;
3 import org.readium.r2_streamer.model.container.Container;
4 import org.readium.r2_streamer.model.publication.EpubPublication;
5 import org.readium.r2_streamer.model.publication.link.Link;
8 * Class to handle parsing of the .cbz (Comic book archive)
9 * ref => https://en.wikipedia.org/wiki/Comic_book_archive
11 * @author gautam chibde on 5/6/17.
14 public class CBZParser {
15 private static final String TAG = CBZParser.class.getSimpleName();
18 * function converts all the images inside the .cbz file into
19 * link and addes them to spine and linkMap
21 * @param container contains implementation for getting raw data from file.
22 * @param publication The `Publication` object resulting from the parsing.
24 public static void parseCBZ(Container container, EpubPublication publication) {
26 publication.internalData.put("type", "cbz");
27 // since all the image files are inside zip rootpath is kept empty
28 publication.internalData.put("rootfile", "");
30 for (String name : container.listFiles()) {
31 Link link = new Link();
32 link.typeLink = getMediaType(name);
34 // Add the book images to the spine element
35 publication.spines.add(link);
36 // Add to the resource linkMap for ResourceHandler to publish on the server
37 publication.linkMap.put(name, link);
42 * Returns the mimetype depending on the file format
44 * @param name file name
45 * @return mimetype of the input file
47 private static String getMediaType(String name) {
48 if (name.contains(".jpg") || name.contains("jpeg")) {
50 } else if (name.contains("png")) {