private File downloadPlugin(PluginInfo info) throws IOException { URL downloadURL = info.getDownloadURL(); final String[] path = downloadURL.getFile().split("/"); String downloadFileName = path[path.length-1]; String tmpPath = System.getProperty("java.io.tmpdir"); File tempPluginFile = new File(tmpPath, downloadFileName); tempPluginFile.deleteOnExit(); URLConnection conn = downloadURL.openConnection(); BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempPluginFile)); while (true) { byte [] buffer = new byte [4068]; int read = bis.read(buffer); if (read == -1) { break; } bos.write(buffer, 0, read); } bis.close(); bos.flush(); bos.close(); // Extract if a zip file if (downloadURL.getFile().endsWith(".zip")){ tempPluginFile = extractPlugin(tempPluginFile, info); } return tempPluginFile; }
private File downloadPlugin(PluginInfo info) throws IOException { URL downloadURL = info.getDownloadURL(); final String[] path = downloadURL.getFile().split("/"); String downloadFileName = path[path.length-1]; String tmpPath = System.getProperty("java.io.tmpdir"); File tempPluginFile = new File(tmpPath, downloadFileName); tempPluginFile.deleteOnExit(); URLConnection conn = downloadURL.openConnection(); BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempPluginFile)); while (true) { byte [] buffer = new byte [4068]; int read = bis.read(buffer); if (read == -1) { break; } bos.write(buffer, 0, read); } bis.close(); bos.flush(); bos.close(); // Extract if a zip file if (downloadURL.getFile().endsWith(".zip")){ tempPluginFile = extractPlugin(tempPluginFile, info); } return tempPluginFile; }
private Optional<File> downloadPlugin(PluginInfo info) throws IOException { URL downloadURL = info.getDownloadURL(); logger.info("Downloading the {} plugin from: {}", info.getLabel(), downloadURL); File tempPluginFile = File.createTempFile(info.getId(), ".jar"); tempPluginFile.deleteOnExit(); URLConnection conn = downloadURL.openConnection(); BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempPluginFile)); while (true) { byte[] buffer = new byte[4068]; int read = bis.read(buffer); if (read == -1) { break; } bos.write(buffer, 0, read); } bis.close(); bos.flush(); bos.close(); logger.info("The {} plugin has been downloaded to {}", info.getLabel(), tempPluginFile.getAbsolutePath()); // Extract if a zip file if (downloadURL.getFile().endsWith(".zip")) { return extractPlugin(tempPluginFile, info); } else { return Optional.of(tempPluginFile); } }