Fast-android-networking: ProtocolException while downloading large files.

Created on 23 Sep 2017  路  7Comments  路  Source: amitshekhariitbhu/Fast-Android-Networking

After fixing the OutOfMemory issue when a large file is downloaded, everything was fine.

But, suddenly found this when I tried files with size more than 40mb. It's working fine for 15-20 MB files.

09-23 22:08:38.716 18289-18289/sample.app W/System.err: com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: java.net.ProtocolException: unexpected end of stream
09-23 22:08:38.721 18289-18289/sample.app  W/System.err: Caused by: com.androidnetworking.error.ANError: java.net.ProtocolException: unexpected end of stream

Can't understand what's happening.

The File was, THIS
[Exe/45mb]

[EDIT] Later I've got some more :

Non-fatal Exception: com.androidnetworking.error.ANError: java.net.ProtocolException: unexpected end of stream
       at com.androidnetworking.internal.InternalNetworking.performDownloadRequest(InternalNetworking.java:210)
       at com.androidnetworking.internal.InternalRunnable.executeDownloadRequest(InternalRunnable.java:102)
       at com.androidnetworking.internal.InternalRunnable.run(InternalRunnable.java:57)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at com.androidnetworking.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:47)
       at java.lang.Thread.run(Thread.java:848)
Caused by java.net.ProtocolException: unexpected end of stream
       at okhttp3.internal.http1.Http1Codec$FixedLengthSource.read(Http1Codec.java:387)
       at okio.RealBufferedSource.read(RealBufferedSource.java:45)
       at okio.ForwardingSource.read(ForwardingSource.java:35)
       at com.androidnetworking.internal.ResponseProgressBody$1.read(ResponseProgressBody.java:76)
       at okio.RealBufferedSource$1.read(RealBufferedSource.java:409)
       at java.io.InputStream.read(InputStream.java:162)
       at com.androidnetworking.utils.Utils.saveFile(Utils.java:188)
       at com.androidnetworking.internal.InternalNetworking.performDownloadRequest(InternalNetworking.java:185)
       at com.androidnetworking.internal.InternalRunnable.executeDownloadRequest(InternalRunnable.java:102)
       at com.androidnetworking.internal.InternalRunnable.run(InternalRunnable.java:57)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at com.androidnetworking.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:47)
       at java.lang.Thread.run(Thread.java:848)

All 7 comments

Checking the issue.
Have you enabled the logging?
Also refer this issue.

Enabled, Today I've tried a bigger(~60mb) file 3 times, found it working fine. Just confused what's happening.

once disable the logging and try it out.

Okay: From okhttp3.internal.http1

/** An HTTP body with a fixed length specified in advance. */
  private class FixedLengthSource extends AbstractSource {
    private long bytesRemaining;

    public FixedLengthSource(long length) throws IOException {
      bytesRemaining = length;
      if (bytesRemaining == 0) {
        endOfInput(true);
      }
    }

    @Override public long read(Buffer sink, long byteCount) throws IOException {
      if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
      if (closed) throw new IllegalStateException("closed");
      if (bytesRemaining == 0) return -1;

      long read = source.read(sink, Math.min(bytesRemaining, byteCount));
      if (read == -1) {
        endOfInput(false); // The server didn't supply the promised content length.
        throw new ProtocolException("unexpected end of stream");
      }

I just want to know if there is any way to ignore error caused from The server didn't supply the promised content length.

_I just want to download what the server supplies, not exactly what he tells._

Please help, @amitshekhariitbhu

@ExploiTR I will try it.

Many thanks.

Just comment out the bellow code or off the debug. It works for me

//if (BuildConfig.DEBUG) {
// AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY)
// }/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amervelic picture amervelic  路  3Comments

MahdiPishguy picture MahdiPishguy  路  5Comments

GulajavaMinistudio picture GulajavaMinistudio  路  3Comments

amervelic picture amervelic  路  4Comments

rezasadeghi93 picture rezasadeghi93  路  8Comments