private static Download fillDownloadable()

in geronimo-microprofile-site/src/main/java/org/apache/geronimo/microprofile/site/Downloads.java [214:248]


    private static Download fillDownloadable(final Download download) {
        final int maxRetries = 3;
        for (int i = 0; i < maxRetries; i++) {
            try {
                final URL url = new URL(download.url);
                final HttpURLConnection connection = HttpURLConnection.class.cast(url.openConnection());
                connection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(30));
                final int responseCode = connection.getResponseCode();
                if (responseCode != HttpURLConnection.HTTP_OK) {
                    if (HttpURLConnection.HTTP_NOT_FOUND != responseCode) {
                        System.err.println("Got " + responseCode + " for " + download.url);
                    }
                    return null;
                }

                download.setDate(connection.getHeaderField("Last-Modified").replaceAll(" +", " "));
                download.setSize(toMega(ofNullable(connection.getHeaderField("Content-Length")).map(Long::parseLong).orElse(0L),
                        ofNullable(connection.getHeaderField("Accept-Ranges")).orElse("bytes")));

                connection.getInputStream().close();
                break;
            } catch (final IOException e) {
                if (i < maxRetries - 1) {
                    continue;
                }
                if (Boolean.getBoolean("debug")) {
                    e.printStackTrace();
                } else {
                    System.err.println("[ERROR] @fillDownload: " + e.getMessage() + " for " + download);
                }
                return null;
            }
        }
        return download;
    }