Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JamMinecraftLauncher;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.ArrayList;
- public class DownloadsThread implements Runnable{
- String Destination = "";
- ArrayList<String> URLsList;
- public DownloadsThread(ArrayList<String> urlsList, String destination){
- URLsList = urlsList;
- Destination = destination;
- }
- @Override
- public void run() {
- for (String URL:URLsList){
- String[] UrlSplited = URL.split("/");
- String fileName = UrlSplited[UrlSplited.length - 1];
- try {
- downloadFile(URL, Destination + fileName);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- synchronized (GUI.lock) {
- GUI.lock.notify();
- }
- }
- public void downloadFile(String URL, String DestinationPlusName) throws IOException{
- float byteDownloaded = 1;
- URL url = new URL(URL);
- URLConnection connection = url.openConnection();
- InputStream stream = connection.getInputStream();
- BufferedInputStream in = new BufferedInputStream(stream);
- FileOutputStream file = new FileOutputStream(DestinationPlusName);
- BufferedOutputStream out = new BufferedOutputStream(file);
- int i;
- float totalSize = connection.getContentLength();
- while ((i = in.read()) != -1) {
- GUI.progressBarInstall.setValue((int)((byteDownloaded / totalSize) * 100));
- GUI.progressBarInstall.update(GUI.progressBarInstall.getGraphics());
- out.write(i);
- byteDownloaded++;
- }
- out.flush();
- file.close();
- }
- }
Add Comment
Please, Sign In to add comment