File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
arduino-core/src/cc/arduino/utils/network Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 3838import java .io .IOException ;
3939import java .io .InputStream ;
4040import 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 ;
4247import java .util .Observable ;
4348
4449public 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 {
You can’t perform that action at this time.
0 commit comments