EOFException is thrown when reading contents of an ePub file
Asked Answered
M

2

9

I'm trying to read the contents of an ePub file using the library epublib and this example demonstrates that.

For me, an exception is thrown when loading the book from the input stream

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

Not sure why the code isn't working and the exception is thrown for me? It has worked for other users of the StackOverflow.

Full Stack trace is shared 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)
Mohamedmohammad answered 7/4, 2017 at 10:50 Comment(3)
Did you try more than one book file? Are you sure your epub file(s) are properly formatted (readable)? Did you use the right name? Does the file exist?...Digger
Please, check both file location/ directory and file extension.Unhitch
It is not very wise to waste 100 reputation points for a bounty, but then not provide enough information but just a single line of code. Please provide an MCVE with source code, a download link for the EPUB in question and what else could be helpful. Help the community help you, otherwise you will get no meaningful answer.Confident
L
3

EOFException is thrown:

  • if there is no data in a stream but you are trying to read.. eg read methods of chain streams like DataInputStream, ObjectInputStream throw EOFException if they are trying to read from FileInputStream but the FileInputStream is empty or

  • if the formats are not matching...eg if int is present and you are using readFloat() of DataInputStream

Laborer answered 14/4, 2017 at 17:59 Comment(0)
L
0

You should try calling below method 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");
Lafleur answered 16/4, 2017 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.