Added Android code
[wl-app.git] / Android / r2-streamer / r2-fetcher / src / main / java / org / readium / r2_streamer / fetcher / EpubFetcher.java
1 package org.readium.r2_streamer.fetcher;
2
3 import org.readium.r2_streamer.model.container.Container;
4 import org.readium.r2_streamer.model.publication.EpubPublication;
5
6 import java.io.InputStream;
7
8 /**
9  * Created by Shrikant Badwaik on 27-Jan-17.
10  */
11
12 public class EpubFetcher implements Fetcher {
13     private final String TAG = "EpubFetcher";
14     public Container container;
15     public EpubPublication publication;
16     private String rootFileDirectory;
17
18     public EpubFetcher(Container container, EpubPublication publication) throws EpubFetcherException {
19         this.container = container;
20         this.publication = publication;
21
22         String rootPath = publication.internalData.get("rootfile");
23         if (rootPath != null) {
24             this.rootFileDirectory = rootPath;
25         } else {
26             throw new EpubFetcherException("No rootFile in internalData, unable to get path to publication");
27         }
28     }
29
30     @Override
31     public String getData(String path) throws EpubFetcherException {
32         String data = container.rawData(path);
33         if (data == null) {
34             System.out.println(TAG + " file is missing " + path);
35             throw new EpubFetcherException(path + " file is missing");
36         }
37         return data;
38     }
39
40     @Override
41     public int getDataSize(String path) throws EpubFetcherException {
42         int dataSize = container.rawDataSize(path);
43         if (dataSize == 0) {
44             System.out.println(TAG + " file is missing " + path);
45             throw new EpubFetcherException(path + "file is missing");
46         }
47         return dataSize;
48     }
49
50     @Override
51     public InputStream getDataInputStream(String path) throws EpubFetcherException {
52         InputStream dataInputStream = container.rawDataInputStream(path);
53         if (dataInputStream == null) {
54             System.out.println(TAG + " file is missing " + path);
55             throw new EpubFetcherException(path + "file is missing");
56         }
57         return dataInputStream;
58     }
59 }