All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.heroku.sdk.deploy.util.FileDownloader Maven / Gradle / Ivy

There is a newer version: 3.0.7
Show newest version
package com.heroku.sdk.deploy.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;

public class FileDownloader {

    public static Path download(URI uri) throws IOException {
        Path temporaryFilePath = Files.createTempFile("heroku-deploy-file-downloader", ".tmp");

        FileOutputStream fileOutputStream = new FileOutputStream(temporaryFilePath.toFile());
        ReadableByteChannel readableByteChannel = Channels.newChannel(uri.toURL().openStream());

        fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);

        return temporaryFilePath;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy