mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Added support to file:// protocol. Fixes #4098
This commit is contained in:
parent
2747fddd10
commit
960918796e
@ -38,7 +38,12 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Observable;
|
||||
|
||||
public class FileDownloader extends Observable {
|
||||
@ -112,6 +117,24 @@ public class FileDownloader extends Observable {
|
||||
}
|
||||
|
||||
public void download() throws InterruptedException {
|
||||
if ("file".equals(downloadUrl.getProtocol())) {
|
||||
saveLocalFile();
|
||||
} else {
|
||||
downloadFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLocalFile() {
|
||||
try {
|
||||
Files.write(outputFile.toPath(), Files.readAllBytes(Paths.get(downloadUrl.getPath())));
|
||||
setStatus(Status.COMPLETE);
|
||||
} catch (Exception e) {
|
||||
setStatus(Status.ERROR);
|
||||
setError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadFile() throws InterruptedException {
|
||||
RandomAccessFile file = null;
|
||||
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user