Bugs : Zlib Out of Memory

sioconcept

Active Member
Licensed User
Longtime User
Hi,

I would like to unzip with zlib (thanks for RandomAccessFile libs) but when my file is too big (5 Mo zipped, 20 Mo uncompressed), i've this error :

B4X:
[B]java.lang.OutOfMemoryError[/B]


   at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
   at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
   at anywheresoftware.b4a.objects.streams.File.Copy2(File.java:337)
   at anywheresoftware.b4a.randomaccessfile.CompressedStreams.DecompressBytes(CompressedStreams.java:135)
   at com.agartha.main._jobdone(main.java:1062)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
   at anywheresoftware.b4a.keywords.Common$4.run(Common.java:885)
   at android.os.Handler.handleCallback(Handler.java:615)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:153)
   at android.app.ActivityThread.main(ActivityThread.java:5086)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
   at dalvik.system.NativeStart.main(Native Method)

The program work well when the size of ziped file is more little, nothing error.
 

sioconcept

Active Member
Licensed User
Longtime User
[RESOLVED] Bugs : Zlib Out of Memory

I've find the problem; the stream is in Json Stream and, because data is big, the json is not good.
So, i don't pass the stream by JSon and i use WrapInputStream (thks Erel)

This is the code (don't forget to changing the job's name, file destination and use libs httpUtils2service):

B4X:
Sub JobDone (Job As HttpJob)

   Dim In As InputStream
   Dim Out As OutputStream
   Dim CS As CompressedStreams

   If Job.Success = True AND Job.JobName == "install" Then
      
      ProgressDialogShow("Unzip progress" & CRLF & "Please wait ...")
      
      In = CS.WrapInputStream(Job.GetInputStream, "gzip")
      Out = File.OpenOutput(File.DirInternal, "file-example.ext", False)
      File.Copy2(In, Out)
      Out.Close

      ProgressDialogHide
      
   End If
   
   Job.Release
   
End Sub

P.S. : The stream is uncompressed in only 1 second for 5 Mo zipped to 20 Mo unzipped (Oo sweat !) on device 2x1 Ghz
 
Last edited:
Top