private Result download() throws IOException { downloadExecutor.updateState(Downloading); Long contentLength = getDownload().getFile().getExpectedChecksum() != null ? getDownload().getFile().getExpectedChecksum().getContentLength() : null; log.info(format("Downloading %d bytes from %s with ETag %s", contentLength, getDownload().getUrl(), getDownload().getETag())); Get get = new Get(getDownload().getUrl()); get.setSocketTimeout(SOCKET_TIMEOUT); if (new Validator(getDownload()).isExistsTargets() && getDownload().getETag() != null) get.setIfNoneMatch(getDownload().getETag()); InputStream inputStream = get.executeAsStream(); log.info(format("Download from %s returned with status code %s and content length %d", getDownload().getUrl(), get.getStatusCode(), get.getContentLength())); if (get.isSuccessful() && inputStream != null) { if(contentLength == null) contentLength = get.getContentLength(); if (contentLength != null) getModelUpdater().expectingBytes(contentLength); new Copier(getModelUpdater()).copyAndClose(inputStream, new FileOutputStream(getDownload().getTempFile()), 0, contentLength); getDownload().setETag(get.getETag()); return new Result(true, get.getLastModified()); } return new Result(get.isSuccessful(), get.isNotModified()); }