/** * Post remote download activity (install and cleanup). Executed in context of the downloader thread. */ private String postRemoteDownload(String jobId) { String result = null; DownloadJob dnld = jobs.get(jobId); S3TemplateDownloader td = (S3TemplateDownloader)dnld.getTemplateDownloader(); if (td.getFileExtension().equalsIgnoreCase("QCOW2")) { // The QCOW2 is the only format with a header, // and as such can be easily read. try (InputStream inputStream = td.getS3ObjectInputStream();) { dnld.setTemplatesize(QCOW2Utils.getVirtualSize(inputStream)); } catch (IOException e) { result = "Couldn't read QCOW2 virtual size. Error: " + e.getMessage(); } } else { // For the other formats, both the virtual // and actual file size are set the same. dnld.setTemplatesize(td.getTotalBytes()); } dnld.setTemplatePhysicalSize(td.getTotalBytes()); dnld.setTmpltPath(td.getDownloadLocalPath()); return result; }