A couple of days ago, the Epub reader library was added here , I tried to use it, but it has some difficulties, it can open Epubs only from resources, but not from the file system, so I decided to download the source and make some adaptation. First, I wrote a small function that opens an Epub file as a stream:
public static InputStream GetFileAsStream(String fName) { FileConnection fconn = null; DataInputStream is = null; try { fconn = (FileConnection) Connector .open(fName, Connector.READ_WRITE); is = fconn.openDataInputStream(); } catch (IOException e) { System.out.println(e.getMessage()); return is;
Then I replaced the call that opens the file in com.omt.epubreader.domain.epub.java , so it became something like this:
public Book getBook(String url) { InputStream in = ConnectionController.GetFileAsStream(url); ... return book; }
after that I was able to read the file successfully, but a problem arose, it could not read the sections, i.e. .html files, so I went into a short debugging session before I found the problem, whoever wrote this library, left the code that read the .html file names empty, in com.omt.epubreader.parser.NcxParser it was something like this:
private void getBookNcxInfo() { ... if(pars.getEventType() == XmlPullParser.START_TAG && pars.getName().toLowerCase().equals(TAG_CONTENT)) { if(pars.getAttributeCount()>0) { } } ... }
I just added this line to the if clause:
contentDataFileName.addElement(pars.getAttributeValue("", "src"));
and after that it worked perfectly.