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)
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
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");
Related
I want to simulate android.database.CursorWindowAllocationException crash. I am working on a huge codebase with a lot of room database queries in each screen. I am not sure in which database query this crash occurs and in which scenario this crash occurs. So is there any way to simulate this crash? I tried keeping almost 10 database cursors open in a for loop but could not reproduce the crash. I have attached the crashlytics logs for reference.
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
at android.database.CursorWindow.<init>(CursorWindow.java:108)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:309)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:147)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:141)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:220)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:269)
at androidx.room.InvalidationTracker$1.checkUpdatedTable(InvalidationTracker.java:461)
at androidx.room.InvalidationTracker$1.run(InvalidationTracker.java:431)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
The following simulates such a crash (but traps it):-
var lastIndex = 0
try
{
for (i in 0..1999) {
lastIndex = i
val csr: Cursor = db.openHelper.writableDatabase.query(SimpleSQLiteQuery("SELECT * FROM model"))
val count = csr.count.toLong()
}
}catch ( e:java.lang.Exception)
{
Log.d(
"DBEXCEPTION",
"Exception trapped at INDEX " + lastIndex + " Message was " + e.message
)
e.printStackTrace()
}
}
where db is an instance of an #Database annotated class (etc).
0..1999 as 2000 open Cursors should be enough to always fail
note that empty Cursors do not appear to result in a failure and not actually traversing the Cursor in some way doesn't result in the a failure. hence the csr.count.toLong
I suspect that the file underlying the Cursor is created/opened and closed properly by SQLite and it is not until an attempt is made to access the Cursor that the file is actually opened and then left open until the file is closed.
The log will then contain something like:-
2022-09-20 09:48:01.929 E/CursorWindow: CursorWindow: mmap() failed: errno=12.
2022-09-20 09:48:01.930 D/DBEXCEPTION: Exception trapped at INDEX 1415 Message was Could not allocate CursorWindow '/data/user/0/a.a.so73757679kotlinroomuniqueconflict/databases/the_database.db' of size 2097152 due to error -12.
2022-09-20 09:48:01.930 W/System.err: android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/data/user/0/a.a.so73757679kotlinroomuniqueconflict/databases/the_database.db' of size 2097152 due to error -12.
2022-09-20 09:48:01.930 W/System.err: at android.database.CursorWindow.nativeCreate(Native Method)
2022-09-20 09:48:01.930 W/System.err: at android.database.CursorWindow.<init>(CursorWindow.java:139)
2022-09-20 09:48:01.930 W/System.err: at android.database.CursorWindow.<init>(CursorWindow.java:120)
2022-09-20 09:48:01.930 W/System.err: at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:202)
2022-09-20 09:48:01.931 W/System.err: at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:147)
2022-09-20 09:48:01.931 W/System.err: at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:140)
2022-09-20 09:48:01.931 W/System.err: at android.app.Activity.performCreate(Activity.java:7994)
2022-09-20 09:48:01.931 W/System.err: at android.app.Activity.performCreate(Activity.java:7978)
2022-09-20 09:48:01.931 W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
2022-09-20 09:48:01.931 W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
2022-09-20 09:48:01.931 W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
2022-09-20 09:48:01.931 W/System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
2022-09-20 09:48:01.931 W/System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
2022-09-20 09:48:01.931 W/System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
2022-09-20 09:48:01.931 W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
2022-09-20 09:48:01.932 W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
2022-09-20 09:48:01.932 W/System.err: at android.os.Looper.loop(Looper.java:223)
2022-09-20 09:48:01.932 W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7656)
2022-09-20 09:48:01.932 W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2022-09-20 09:48:01.932 W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
2022-09-20 09:48:01.932 W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2022-09-20 09:48:02.003 W/libc: malloc(4194304) failed: returning null pointer
2022-09-20 09:48:02.003 A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x80000 in tid 23176 (RenderThread), pid 23153 (muniqueconflict)
It should be noted that the issue at hand is not exactly the number of Cursors but that underlying a Cursor is a file and that (I believe) the issue is the number of unclosed file allocations of which the database itself will have 3 (for the database, the -wal file and the -shm file).
However, there may also be a memory related issue, as this test then results in the malloc error (failed to get 4Mb).
I am integrating the Intercom plugin for an existing Ionic 5 application following the instructions here: https://ionicframework.com/docs/native/intercom. Everything works great iOS, but when I start the application in an android simulator, the following exception is thrown and the app terminates.
I am fairly new to android studio/java, so any advice would be greatly appreciated.
D/Capacitor: Starting BridgeActivity
W/System.err: java.lang.ClassNotFoundException: io.intercom.android.sdk.IntercomBridge
W/System.err: at java.lang.Class.classForName(Native Method)
W/System.err: at java.lang.Class.forName(Class.java:454)
W/System.err: at java.lang.Class.forName(Class.java:379)
W/System.err: at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:564)
W/System.err: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:183)
W/System.err: at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:108)
W/System.err: at org.apache.cordova.PluginManager.init(PluginManager.java:96)
W/System.err: at com.getcapacitor.cordova.MockCordovaWebViewImpl.init(MockCordovaWebViewImpl.java:58)
W/System.err: at com.getcapacitor.Bridge$Builder.create(Bridge.java:1303)
W/System.err: at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:72)
W/System.err: at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:58)
W/System.err: at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:41)
W/System.err: at com.rkkn.driversseatcoop2.MainActivity.onCreate(MainActivity.java:15)
W/System.err: at android.app.Activity.performCreate(Activity.java:8054)
W/System.err: at android.app.Activity.performCreate(Activity.java:8034)
W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1341)
W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3666)
W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3842)
W/System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
W/System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
W/System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2252)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err: at android.os.Looper.loopOnce(Looper.java:201)
W/System.err: at android.os.Looper.loop(Looper.java:288)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7842)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "io.intercom.android.sdk.IntercomBridge" on path: DexPathList[[zip file
dd
[1]: https://ionicframework.com/docs/v5/native/intercom
After getting facebook access token, i use it for login in my own web server. However in the first time, there is warning in the log file, and i can not load data from my server, but when i open app from second times, it load normally.
Below is warning log:
W/System.err: com.google.gson.JsonSyntaxException:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
at line 1 column 1 path $ W/System.err: at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
W/System.err: at
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
W/System.err: at
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
W/System.err: at
retrofit2.ServiceMethod.toResponse(ServiceMethod.java:122)
W/System.err: at
retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:217) W/System.err:
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180) W/System.err:
at
retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42) W/System.err: at
io.reactivex.Observable.subscribe(Observable.java:12084) W/System.err:
at
retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
W/System.err: at
io.reactivex.Observable.subscribe(Observable.java:12084) W/System.err:
at
io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
W/System.err: at io.reactivex.Single.subscribe(Single.java:3433)
W/System.err: at
io.reactivex.internal.operators.single.SingleDoOnSuccess.subscribeActual(SingleDoOnSuccess.java:35)
W/System.err: at io.reactivex.Single.subscribe(Single.java:3433)
W/System.err: at
io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
W/System.err: at
io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:579)
W/System.err: at
io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
W/System.err: at
io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
W/System.err: at
java.util.concurrent.FutureTask.run(FutureTask.java:266) W/System.err:
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W/System.err: at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err: at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err: at java.lang.Thread.run(Thread.java:764)
W/System.err: Caused by: java.lang.IllegalStateException: Expected
BEGIN_OBJECT but was STRING at line 1 column 1 path $ W/System.err:
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
W/System.err: at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213)
What could be causing this?
That error tells you that there is an error when GSON tries to parse the JSON returned by the web service you're calling. In particular, GSON is expecting a JSON object, but it receives a string (see the first line of the error message).
If the error happens only the first time you call it and not the second it means that the web service returns 2 different answers, and GSON can correctly parse the second one, but not the first one.
In order to find out what's wrong, you should provide more details, like your data model and the 2 responses returned by the web service.
Good evening,
I have written a java library using JAXB (javax.xml.bind:jaxb-api:2.1), which works just fine in my desktop-application.
Now I want to use this library on android, but when I try to create the JAXBContext:
JAXBContext context =
JAXBContext.newInstance(ObjectFactory.class.getPackage().getName(),
this.getClass().getClassLoader());
I get this error (see stacktrace below).
I would appreciate any hint in which direction I have to look.
Thanks in advance!!
Stacktrace:
W/System.err: java.util.MissingResourceException: Can't find bundle for base name javax.xml.bind.Messages, locale de_DE
W/System.err: at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1501)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1324)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:723)
at javax.xml.bind.Messages.format(Messages.java:71)
at javax.xml.bind.Messages.format(Messages.java:56)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:371)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:446)
W/System.err: at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:409)
at org.foo.mylibraryapi.persistence.adapter.ModelReader.readDocument(ModelReader.java:67)
at org.foo.mylibraryapi.persistence.adapter.ModelReader.readDocument(ModelReader.java:30)
at org.foo.mylibrary.ui.FileLoader.load(FileLoader.java:14)
at org.foo.ambitusapp.MainActivity.onActivityResult(MainActivity.java:180)
at android.app.Activity.dispatchActivityResult(Activity.java:6946)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4126)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4173)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
W/System.err: Caused by: java.lang.ClassCastException: javax.xml.bind.Messages cannot be cast to ResourceBundle
at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2576)
at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1438)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1402)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1356)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1356)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1298)
... 22 more
I tried adding a retry policy (https://stackoverflow.com/a/22169775/2098493)
but the error persist when file being uploaded is larger than 1mb.
W/System.err: com.android.volley.NoConnectionError: javax.net.ssl.SSLException: Write error: ssl=0xafc3fe00: I/O error during system call, Connection reset by peer
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:151)
W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
W/System.err: Caused by: javax.net.ssl.SSLException: Write error: ssl=0xafc3fe00: I/O error during system call, Connection reset by peer
W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:765)
W/System.err: at com.android.okio.Okio$1.write(Okio.java:70)
W/System.err: at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
W/System.err: at com.android.okio.RealBufferedSink.write(RealBufferedSink.java:44)
W/System.err: at com.android.okhttp.internal.http.RetryableSink.writeToSocket(RetryableSink.java:77)
W/System.err: at com.android.okhttp.internal.http.HttpConnection.writeRequestBody(HttpConnection.java:240)
W/System.err: at com.android.okhttp.internal.http.HttpTransport.writeRequestBody(HttpTransport.java:77)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:622)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
W/System.err: at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
W/System.err: at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110)
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
Thanks for your advice.
The solution was a combination of adding Volley Retry Policy and making sure back-end and server (nodejs/nginx) max uploaded file size are both set correctly.
//where RETRY_DEFAULT_TIMEOUT_MS = 5000, RETRY_DEFAULT_MAX_RETRIES = 3, RETRY_DEFAULT_BACKOFF_MULT = 2.0f
request.setRetryPolicy(new DefaultRetryPolicy(RETRY_DEFAULT_TIMEOUT_MS,
RETRY_DEFAULT_MAX_RETRIES,
RETRY_DEFAULT_BACKOFF_MULT));