@@ -933,15 +933,28 @@ public static String discoverKey() {
933933 }
934934 return key ;
935935 }
936-
937- public static File download (String version , String downloadJsonURL , long sizeOfJson , String bindir , String filename ,
936+ /**
937+ *
938+ * @param version A string indicating version, this will be the folder name
939+ * @param URL The direct URL of the download
940+ * @param sizeOfFile The number of bytes in the file
941+ * @param directoryInWhichFileIsStored The root directory into which this will all be downloaded
942+ * @param filename The resulting filename
943+ * @param downloadName User level name for asking about the download
944+ * @return
945+ * @throws MalformedURLException
946+ * @throws IOException
947+ * @throws FileNotFoundException
948+ * @throws InterruptedException
949+ */
950+ public static File download (String version , String URL , long sizeOfFile , String directoryInWhichFileIsStored , String filename ,
938951 String downloadName )
939952 throws MalformedURLException , IOException , FileNotFoundException , InterruptedException {
940953
941- URL url = new URL (downloadJsonURL );
954+ URL url = new URL (URL );
942955 URLConnection connection = url .openConnection ();
943956 InputStream is = connection .getInputStream ();
944- ProcessInputStream pis = new ProcessInputStream (is , (int ) sizeOfJson );
957+ ProcessInputStream pis = new ProcessInputStream (is , (int ) sizeOfFile );
945958 pis .addListener (new Listener () {
946959 long timeSinceePrint = System .currentTimeMillis ();
947960
@@ -962,28 +975,16 @@ public void process(double percent) {
962975
963976 if (!folder .exists () || !exe .exists ()) {
964977
965- if (approval .get (downloadName , downloadJsonURL )) {
978+ if (approval .get (downloadName , URL )) {
966979 com .neuronrobotics .sdk .common .Log .error ("Start Downloading " + filename );
967- com .neuronrobotics .sdk .common .Log .error ("From " +downloadJsonURL );
980+ com .neuronrobotics .sdk .common .Log .error ("From " +URL );
968981
969982 } else {
970983 pis .close ();
971984 throw new RuntimeException ("No Application insalled" );
972985 }
973986 downloadEvents .startDownload ();
974- folder .mkdirs ();
975- exe .createNewFile ();
976- byte dataBuffer [] = new byte [1024 *1000 ];
977- int bytesRead ;
978- FileOutputStream fileOutputStream = new FileOutputStream (exe .getAbsoluteFile ());
979- int chunks =0 ;
980- while ((bytesRead = pis .read (dataBuffer , 0 , dataBuffer .length )) != -1 ) {
981- fileOutputStream .write (dataBuffer , 0 , bytesRead );
982- //psudoSplash.onUpdate((int) (chunks++)+" Kb " +filename , null);
983-
984- }
985- fileOutputStream .close ();
986- pis .close ();
987+ rawFileDownload (pis , folder , exe );
987988 com .neuronrobotics .sdk .common .Log .error ("Finished downloading " + filename );
988989 psudoSplash .onUpdate ((int ) (1 * 100 )+" % " +filename , null );
989990 downloadEvents .finishDownload ();
@@ -992,6 +993,22 @@ public void process(double percent) {
992993 }
993994 return exe ;
994995 }
996+ private static void rawFileDownload (ProcessInputStream pis , File folder , File exe )
997+ throws IOException , FileNotFoundException {
998+ folder .mkdirs ();
999+ exe .createNewFile ();
1000+ byte dataBuffer [] = new byte [1024 *1000 ];
1001+ int bytesRead ;
1002+ FileOutputStream fileOutputStream = new FileOutputStream (exe .getAbsoluteFile ());
1003+ int chunks =0 ;
1004+ while ((bytesRead = pis .read (dataBuffer , 0 , dataBuffer .length )) != -1 ) {
1005+ fileOutputStream .write (dataBuffer , 0 , bytesRead );
1006+ //psudoSplash.onUpdate((int) (chunks++)+" Kb " +filename , null);
1007+
1008+ }
1009+ fileOutputStream .close ();
1010+ pis .close ();
1011+ }
9951012
9961013 /**
9971014 * @return the editorsURL
0 commit comments