2017-03-22 3 views
2

Ich versuche, zip-Datei (Größe 160 Mb) über okhttp3 herunterladen. Nach ein paar Sekunden app Absturz mit Stack:OutOfMemoryError in okhttp3 große Datei herunterladen

java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread. at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) Caused by: java.lang.OutOfMemoryError: Failed to allocate a 8204 byte allocation with 1688 free bytes and 1688B until OOM at okio.Segment.(Segment.java:61) at okio.SegmentPool.take(SegmentPool.java:46) at okio.Buffer.writableSegment(Buffer.java:1151) at okio.Okio$2.read(Okio.java:136) at okio.AsyncTimeout$2.read(AsyncTimeout.java:238) at okio.RealBufferedSource.read(RealBufferedSource.java:45) at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:377) at okio.RealBufferedSource.request(RealBufferedSource.java:66) at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:238) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170) at okhttp3.RealCall.execute(RealCall.java:60) at com.bvs.data.MapService$2.call(MapService.java:102) at com.bvs.data.MapService$2.call(MapService.java:94) at rx.Observable.unsafeSubscribe(Observable.java:10142)

Hier ist mein Code:

Observable.create((Observable.OnSubscribe<ResponseBody>) subscriber -> { 
     Timber.e("Start zip loading"); 
     Request request = new Request.Builder() 
       .url(Tweakables.DEV_API_ENDPOINT + "files/" + Tweakables.MAP_ZIP) 
       .build(); 
     try { 
      Response response = client.newCall(request).execute(); // Crash appeared at this line 
      subscriber.onNext(response.body()); 
      response.close(); 
     } catch (IOException e) { 
      subscriber.onError(e); 
     } 
    }) 
      .subscribeOn(Schedulers.io()) 
      .observeOn(AndroidSchedulers.mainThread()) 
      .subscribe(new Observer<ResponseBody>() { 
       @Override 
       public void onCompleted() { 

       } 

       @Override 
       public void onError(Throwable e) { 
        e.printStackTrace(); 
       } 

       @Override 
       public void onNext(ResponseBody responseBody) { 

       } 
      }); 
+1

Verwenden Download-Manager von großen Dateien wie Zip zum Download bereit. – HourGlass

+1

Es kann sein, dass der 'HttpLoggingInterceptor' versucht, den Antworttext zu protokollieren und somit seinen Inhalt in den Speicher zu laden. – miensol

+0

@miensol Ich habe versucht, 'HttpLoggingInterceptor.Level.NONE' gleichen Fehler zu setzen – Drake

Antwort

2

wird vielleicht für jemanden nützlich sein. Gelöst Problem durch die Verwendung Retrofit Anmerkung Streaming

@Streaming 
@GET("files/"+Tweakables.MAP_ZIP) 
Call<ResponseBody> downloadMap(); 
Verwandte Themen