EOFException thrown when reading contents of ePub file

I am trying to read the contents of an ePub file using the epublib library, and this example demonstrates this.

An exception occurs for me when loading a book from the input stream

// Load Book from inputStream Book book = (new EpubReader()).readEpub(epubInputStream); 

Not sure why the code doesn't work, and an exception is thrown for me? It worked for other StackOverflow users.

The Full Stack trace is used below:

 W/System.err: java.io.EOFException W/System.err: at libcore.io.Streams.readFully(Streams.java:83) W/System.err: at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:235) W/System.err: at nl.siegmann.epublib.epub.EpubReader.readResources(EpubReader.java:184) W/System.err: at nl.siegmann.epublib.epub.EpubReader.readEpub(EpubReader.java:94) W/System.err: at nl.siegmann.epublib.epub.EpubReader.readEpub(EpubReader.java:53) W/System.err: at nl.siegmann.epublib.epub.EpubReader.readEpub(EpubReader.java:37) W/System.err: at com.blogspot.gsrikar.ePubViewerActivity.readEPubContents(ePubViewerActivity.java:102) W/System.err: at com.blogspot.gsrikar.ePubViewerActivity.onCreate(ePubViewerActivity.java:88) W/System.err: at android.app.Activity.performCreate(Activity.java:6904) W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266) W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) W/System.err: at android.app.ActivityThread.-wrap17(ActivityThread.java) W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102) W/System.err: at android.os.Looper.loop(Looper.java:148) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7325) W/System.err: at java.lang.reflect.Method.invoke(Native Method) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
+7
android epub epublib
source share
2 answers

An EOFException is thrown :

  • if there is no data in the stream but you are trying to read. For example, read network stream methods, such as DataInputStream, ObjectInputStream throw EOFException , if they try to read from FileInputStream but FileInputStream is empty or

  • if the formats do not match ... for example if an int is present and you are using readFloat () DataInputStream

+2
source share

You should try calling the method below before passing it to readEpub. Java Doc Link: http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#available ()

 //assuming the above variables are already declared. if(epubInputStream.available() > 0) Book book = (new EpubReader()).readEpub(epubInputStream); else System.out.println("no data to read"); 
0
source share

All Articles