private static File download()

in frontend/modelarchive/src/main/java/com/amazonaws/ml/mms/archive/ModelArchive.java [146:185]


    private static File download(String path) throws ModelException, IOException {
        HttpURLConnection conn;
        try {
            URL url = new URL(path);
            conn = (HttpURLConnection) url.openConnection();
            if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new DownloadModelException(
                        "Failed to download model from: "
                                + path
                                + ", code: "
                                + conn.getResponseCode());
            }
        } catch (MalformedURLException | RuntimeException e) {
            // URLConnection may throw raw RuntimeException if port is out of range.
            throw new ModelNotFoundException("Invalid model url: " + path, e);
        } catch (IOException e) {
            throw new DownloadModelException("Failed to download model from: " + path, e);
        }

        try {
            String eTag = conn.getHeaderField("ETag");
            File tmpDir = new File(System.getProperty("java.io.tmpdir"));
            File modelDir = new File(tmpDir, "models");
            FileUtils.forceMkdir(modelDir);
            if (eTag != null) {
                if (eTag.startsWith("\"") && eTag.endsWith("\"") && eTag.length() > 2) {
                    eTag = eTag.substring(1, eTag.length() - 1);
                }
                File dir = new File(modelDir, eTag);
                if (dir.exists()) {
                    logger.info("model folder already exists: {}", eTag);
                    return dir;
                }
            }

            return unzip(conn.getInputStream(), eTag);
        } catch (SocketTimeoutException e) {
            throw new DownloadModelException("Download model timeout: " + path, e);
        }
    }