A
A
Alexander Vasyuchenko2015-10-21 10:40:05
Android
Alexander Vasyuchenko, 2015-10-21 10:40:05

How to avoid "unexpected end of stream" exception?

Good afternoon!
Wrote file downloader via HTTP protocol (with HttpURLConnection class). Sometimes throws an exception when downloading "unexpected end of stream". No matter how much I tested it, everything is ok. Crashes from other users. On which line of the code the exception is also not known exactly, but after googling, I came to the conclusion that here:
int read = stream.read( buffer );
Here is the code: pastebin.com/XKrrXMWT
What is wrong with it and how to avoid this exception?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question