private void downloadFile(String url, FileNode dest) throws IOException { String sha512Expected; String sha512Found; console.info.println("downloading " + url + " ..."); try { dest.getWorld().validNode(url).copyFile(dest); } catch (IOException e) { dest.deleteFileOpt(); throw new IOException("download failed: " + url + "\nAs a work-around, you can download it manually an place it at " + dest.getAbsolute() + "\nDetails: " + e.getMessage(), e); } try { sha512Expected = dest.getWorld().validNode(url + ".sha512").readString(); } catch (IOException e) { dest.deleteFile(); throw new IOException("failed to download " + url + ".sha512", e); } sha512Expected = sha512Expected.substring(0, sha512Expected.indexOf(' ')); try { sha512Found = dest.digest("SHA-512"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } if (!sha512Expected.equals(sha512Found)) { dest.deleteFile(); throw new IOException("sha512 digest mismatch: " + sha512Expected + " vs" + sha512Found); } }
/** * Copies this to dest. Overwrites existing file and adds to existing directories. * * @throws NodeNotFoundException if this does not exist */ public void copy(Node dest) throws NodeNotFoundException, CopyException { try { if (isDirectory()) { dest.mkdirOpt(); copyDirectory(dest); } else { copyFile(dest); } } catch (FileNotFoundException | CopyException e) { throw e; } catch (IOException e) { throw new CopyException(this, dest, e); } }
dest.getParent().mkdirsOpt(); if (content == null || binary.matches(src.node.getRelative(sourcedir))) { src.node.copyFile(dest); } else { dest.writeString(content.apply(src.node.readString(), childVariables));