private static Boolean downloadFile()

in bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/FileDownloader.java [94:135]


    private static Boolean downloadFile(String fileUrl, String saveDir) {
        HttpURLConnection httpConn = null;
        try {
            URL url = new URL(fileUrl);
            httpConn = (HttpURLConnection) url.openConnection();
            int responseCode = httpConn.getResponseCode();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
                InputStream inputStream = httpConn.getInputStream();
                String saveFilePath = saveDir + File.separator + fileName;

                if (!new File(saveDir).exists()) {
                    new File(saveDir).mkdirs();
                }

                FileOutputStream outputStream = new FileOutputStream(saveFilePath);

                int bytesRead = -1;
                byte[] buffer = new byte[4096];
                while ((bytesRead = inputStream.read(buffer)) != -1) {
                    outputStream.write(buffer, 0, bytesRead);
                }

                outputStream.close();
                inputStream.close();

                log.info("File downloaded: [{}]", saveFilePath);
                return true;
            } else {
                log.info("No file to download. Server replied HTTP code: [{}]", responseCode);
                return false;
            }
        } catch (Exception e) {
            log.error("Error downloading file: {}", e.getMessage());
            return false;
        } finally {
            if (httpConn != null) {
                httpConn.disconnect();
            }
        }
    }