Example usage for com.google.api.client.googleapis.media MediaHttpDownloader setChunkSize

List of usage examples for com.google.api.client.googleapis.media MediaHttpDownloader setChunkSize

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.media MediaHttpDownloader setChunkSize.

Prototype

public MediaHttpDownloader setChunkSize(int chunkSize) 

Source Link

Document

Sets the maximum size of individual chunks that will get downloaded by single HTTP requests.

Usage

From source file:org.blom.martin.stream2gdrive.Stream2GDrive.java

License:Apache License

public static void download(Drive client, HttpTransport ht, String root, String remote, String local,
        boolean progress, float chunkSize) throws IOException {
    OutputStream os;//from ww  w . ja  v  a2 s.co m

    if (local.equals("-")) {
        os = System.out;
    } else {
        File file = new File(local);

        if (file.exists()) {
            throw new IOException(String.format("The local file '%s' already exists", file));
        }

        os = new FileOutputStream(file);
    }

    String link = findFile(client, remote, root == null ? "root" : root).getDownloadUrl();

    MediaHttpDownloader dl = new MediaHttpDownloader(ht, client.getRequestFactory().getInitializer());

    dl.setDirectDownloadEnabled(false);
    dl.setChunkSize(calcChunkSize(chunkSize));

    if (progress) {
        dl.setProgressListener(new ProgressListener());
    }

    dl.download(new GenericUrl(link), os);
}