I am downloading audio files by using AsyncTask. Files are downloading on high speed internet like wifi but app gives error with end of stream on low speed internet like mobile data. My download file code is:
`URLConnection conexion = urle.openConnection();
conexion.connect();
InputStream input = new BufferedInputStream(conexion.getInputStream());
totalSize = conexion.getContentLength();
OutputStream output = new FileOutputStream(st);
byte data[] = new byte[1024];
while ((count = input.read(data)) != -1)
{
output.write(data, 0, count);
downloadedSize += count;
}
output.flush();
output.close();
input.close();`
Following exception is coming:
`java.net.ProtocolException: unexpected end of stream
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSink.close(HttpConnection.java:326)
at com.android.okio.RealBufferedSink.close(RealBufferedSink.java:174)
at com.android.okio.RealBufferedSink$1.close(RealBufferedSink.java:142)`
From this link error is due to (usually set in the content-length header of the response) is larger than the actual data in the response. But how can solve it???