Skip to content

Commit 9609187

Browse files
author
Federico Fissore
committed
Added support to file:// protocol. Fixes #4098
1 parent 2747fdd commit 9609187

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

arduino-core/src/cc/arduino/utils/network/FileDownloader.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
import java.io.IOException;
3939
import java.io.InputStream;
4040
import java.io.RandomAccessFile;
41-
import java.net.*;
41+
import java.net.HttpURLConnection;
42+
import java.net.Proxy;
43+
import java.net.SocketTimeoutException;
44+
import java.net.URL;
45+
import java.nio.file.Files;
46+
import java.nio.file.Paths;
4247
import java.util.Observable;
4348

4449
public class FileDownloader extends Observable {
@@ -112,6 +117,24 @@ public void setStatus(Status status) {
112117
}
113118

114119
public void download() throws InterruptedException {
120+
if ("file".equals(downloadUrl.getProtocol())) {
121+
saveLocalFile();
122+
} else {
123+
downloadFile();
124+
}
125+
}
126+
127+
private void saveLocalFile() {
128+
try {
129+
Files.write(outputFile.toPath(), Files.readAllBytes(Paths.get(downloadUrl.getPath())));
130+
setStatus(Status.COMPLETE);
131+
} catch (Exception e) {
132+
setStatus(Status.ERROR);
133+
setError(e);
134+
}
135+
}
136+
137+
private void downloadFile() throws InterruptedException {
115138
RandomAccessFile file = null;
116139

117140
try {

0 commit comments

Comments
 (0)