File tree 1 file changed +24
-1
lines changed
arduino-core/src/cc/arduino/utils/network 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 38
38
import java .io .IOException ;
39
39
import java .io .InputStream ;
40
40
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 ;
42
47
import java .util .Observable ;
43
48
44
49
public class FileDownloader extends Observable {
@@ -112,6 +117,24 @@ public void setStatus(Status status) {
112
117
}
113
118
114
119
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 {
115
138
RandomAccessFile file = null ;
116
139
117
140
try {
You can’t perform that action at this time.
0 commit comments