Source:
public File download(DownloadJob job, URL src) throws IOException { MessageDigest sha1 = null; try { sha1 = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException ignored) { } URLConnection con = null; try { con = connect(job,src); con.setReadTimeout(PLUGIN_DOWNLOAD_READ_TIMEOUT); int total = con.getContentLength(); byte[] buf = new byte[8192]; int len; File dst = job.getDestination(); File tmp = new File(dst.getPath()+".tmp"); LOGGER.info("Downloading "+job.getName()); Thread t = Thread.currentThread(); String oldName = t.getName(); t.setName(oldName + ": " + src); try { try (OutputStream _out = Files.newOutputStream(tmp.toPath()); OutputStream out = sha1 != null ? new DigestOutputStream(_out, sha1) : _out; InputStream in = con.getInputStream(); CountingInputStream cin = new CountingInputStream(in)) { while ((len = cin.read(buf)) >= 0) { out.write(buf, 0, len); job.status = job.new Installing(total == -1 ? -1 : cin.getCount() * 100 / total); } } } catch (IOException e) { throw new IOException("Failed to load "+src+" to "+tmp,e); } finally { t.setName(oldName); } if (total!=-1 && total!=tmp.length()) { throw new IOException("Inconsistent file length: expected "+total+" but only got "+tmp.length()); } if (sha1 != null) { byte[] digest = sha1.digest(); job.computedSHA1 = Base64.encodeBase64String(digest); } return tmp; } catch (IOException e) { String extraMessage = ""; if (con != null && con.getURL() != null && !src.toString().equals(con.getURL().toString())) { extraMessage = " (redirected to: " + con.getURL() + ")"; } throw new IOException2("Failed to download from "+src+extraMessage,e); } }

Target:
public File download(DownloadJob job, URL src) throws IOException { MessageDigest sha1 = null; try { sha1 = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException ignored) { } URLConnection con = null; try { con = connect(job,src); con.setReadTimeout(PLUGIN_DOWNLOAD_READ_TIMEOUT); int total = con.getContentLength(); byte[] buf = new byte[8192]; int len; File dst = job.getDestination(); File tmp = new File(dst.getPath()+".tmp"); LOGGER.info("Downloading "+job.getName()); Thread t = Thread.currentThread(); String oldName = t.getName(); t.setName(oldName + ": " + src); try (OutputStream _out = Files.newOutputStream(tmp.toPath()); OutputStream out = sha1 != null ? new DigestOutputStream(_out, sha1) : _out; InputStream in = con.getInputStream(); CountingInputStream cin = new CountingInputStream(in)) { while ((len = cin.read(buf)) >= 0) { out.write(buf,0,len); job.status = job.new Installing(total == -1 ? -1 : cin.getCount() * 100 / total); } } catch (IOException e) { throw new IOException("Failed to load "+src+" to "+tmp,e); } finally { t.setName(oldName); } if (total!=-1 && total!=tmp.length()) { throw new IOException("Inconsistent file length: expected "+total+" but only got "+tmp.length()); } if (sha1 != null) { byte[] digest = sha1.digest(); job.computedSHA1 = Base64.encodeBase64String(digest); } return tmp; } catch (IOException e) { String extraMessage = ""; if (con != null && con.getURL() != null && !src.toString().equals(con.getURL().toString())) { extraMessage = " (redirected to: " + con.getURL() + ")"; } throw new IOException2("Failed to download from "+src+extraMessage,e); } }