Newer
Older
sklauncher / src / main / java / com / skcraft / launcher / update / FileDownloader.java
@sk89q sk89q on 9 Jan 2014 1 KB Initial commit.
/*
 * SK's Minecraft Launcher
 * Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> and contributors
 * Please see LICENSE.txt for license information.
 */

package com.skcraft.launcher.update;

import lombok.Getter;
import lombok.ToString;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;

@ToString(exclude = "installer")
public class FileDownloader implements Runnable {

    private final Installer installer;
    @Getter private final URL url;
    @Getter private final List<File> targets;

    public FileDownloader(Installer installer, URL url, List<File> targets) {
        this.installer = installer;
        this.url = url;
        this.targets = targets;
    }

    @Override
    public void run() {
        try {
            File sourceFile = installer.download(url, "");
            installer.submit(new FileDistribute(sourceFile, targets));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (IOException e) {
            throw new RuntimeException("Failed to download " + url, e);
        }
    }

}