aboutsummaryrefslogtreecommitdiffstats
path: root/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/filedistribution/Downloader.java
blob: 0692d3ee499e885358c48c11174803598c19d0c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.proxy.filedistribution;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hmusum
 */
interface Downloader {

    Optional<File> downloadFile(String url, File downloadDir) throws IOException;

    default String fileName() { return "contents"; }

    default boolean alreadyDownloaded(Downloader downloader, File downloadDir) {
        File contents = new File(downloadDir, downloader.fileName());
        return contents.exists() && contents.length() > 0;
    }

}