CB-6928: Implements NOT_MODIFIED check downloading resources.

As described in the issue https://issues.apache.org/jira/browse/CB-6928
A 304 status code will corrupt the transferred resource. This patch checks the status code and if the resource is cached, return as success with no actions.

I've move also the OutputStream declaration to use only if it's necessary and avoid unnecessary extra close method call.