Hello!
Obviously, since I can't use an HTTP-related class like any sane programmer would do, this is an assignment.
So I'm given a URL that directly links to an image. My task is to download that image to a local file. I've written a class for it that does the job of separating the HTTP header from the rest of the stream, and writes the file. I've compared normally-downloaded image file with the one I've downloaded using this class, and size-wise they have a very small difference. For some reason, however, they are not identical and the one that I download through
Java does not open. So far I wasn't able to figure out the problem.
The biggest problem is that I need to separate the header from the rest of the response, and outside of using a BufferedReader I see no other way of doing it without having to write temporary files and removing the header manually.
All of the StackOverflow answers to similiar questions only provide either methods that use HTTP-related classes (easy as pie) or methods that read the entire byte stream and don't separate the header.
Here's my code: