Source:
<code>public void downloadPart(DataChannel channel, Part part, String objectId, File outputDir) throws IOException { retry.execute(new RetryCallback<Void, IOException>() { @Override public Void doWithRetry(RetryContext ctx) throws IOException { log.debug("Download Part URL: {}", part.getUrl()); final RequestCallback requestCallback = new RequestCallback() { @Override public void doWithRequest(final ClientHttpRequest request) throws IOException { request.getHeaders().set(HttpHeaders.RANGE, Parts.getHttpRangeValue(part)); } }; final ResponseExtractor<String> headersExtractor = new ResponseExtractor<String>() { @Override public String extractData(ClientHttpResponse response) throws IOException { try (HashingInputStream his = new HashingInputStream(Hashing.md5(), response.getBody())) { channel.readFrom(his); return his.hash().toString(); } } }; try { log.debug("performing GET {}", part.getUrl()); val md5 = dataTemplate.execute(new URI(part.getUrl()), HttpMethod.GET, requestCallback, headersExtractor); part.setMd5(md5); if (part.hasFailedChecksum()) { val msg = String.format("Checksum failed for Part# %d: %s", part.getPartNumber(), part.getMd5()); <START> throw new Exception(msg); <END> } downloadStateStore.commit(outputDir, objectId, part); log.debug("committed part# to download state store", objectId, part.getPartNumber()); } catch (NotResumableException | NotRetryableException e) { log.error("Cannot proceed. Failed to receive part for part# : {}", part.getPartNumber(), e.getMessage()); throw e; } catch (Throwable e) { log.warn("Failed to receive part for part number: {}. Retrying. {}", part.getPartNumber(), e.getMessage()); channel.reset(); throw new RetryableException(e); } return null; } }); }</code><technical_language>checkState instead. throw amore informative exception reads removes a branch: java checkState(!part.hasFailedChecksum(), "Checksum failed for Part# %d: %s", part.getPartNumber(), part.getMd5());</technical_language>

Target:
public void downloadPart(DataChannel channel, Part part, String objectId, File outputDir) throws IOException { retry.execute(new RetryCallback<Void, IOException>() { @Override public Void doWithRetry(RetryContext ctx) throws IOException { log.debug("Download Part URL: {}", part.getUrl()); try { log.debug("performing GET {}", part.getUrl()); String md5 = dataTemplate.execute(new URI(part.getUrl()), HttpMethod.GET, request -> request.getHeaders().set(HttpHeaders.RANGE, Parts.getHttpRangeValue(part)), response -> { try (HashingInputStream his = new HashingInputStream(Hashing.md5(), response.getBody())) { channel.readFrom(his); return his.hash().toString(); } } ); part.setMd5(md5); checkState(!part.hasFailedChecksum(), "Checksum failed for Part# %d: %s", part.getPartNumber(), part.getMd5()); downloadStateStore.commit(outputDir, objectId, part); log.debug("committed part# to download state store", objectId, part.getPartNumber()); } catch (NotResumableException | NotRetryableException e) { log.error("Cannot proceed. Failed to receive part for part# : {}", part.getPartNumber(), e.getMessage()); throw e; } catch (Throwable e) { log.warn("Failed to receive part for part number: {}. Retrying. {}", part.getPartNumber(), e.getMessage()); channel.reset(); throw new RetryableException(e); } return null; } }); }