@@ -34,6 +34,20 @@ private FLUFiles() {} // hide constructor
34
34
// GET SET ----------------------------------------------------------------------
35
35
public static FLUProgression getProgression () { return progression ; }
36
36
public static void setProgression (FLUProgression progression ) { FLUFiles .progression = progression ; }
37
+ private static void setDownloadingValue (double value ) {
38
+ if (progression != null ) {
39
+ progression .setDownloadingValue (value );
40
+ }
41
+ }
42
+ private static void setDownloadingMessage (String message ) {
43
+ if (progression != null ) {
44
+ progression .setDownloadingMessage (message );
45
+ }
46
+ }
47
+
48
+ // TODO add progressions to all functions that might be long opperation:
49
+ // delete, copy, move, readFile, readFileAsList, readFileFromWeb, writeFile, appendToFile, listFiles, zip, unzip, download,
50
+ // downloadAndUnzip, downloadAndRead, countEntryOfZipFile, getSize
37
51
38
52
public static boolean isAValidePath (String path ) { return internal .isAValidePath (path ); }
39
53
public static boolean createFile (String path ) { return internal .createFile (path ); }
@@ -77,9 +91,19 @@ private FLUFilesInternal() {} // hide constructor
77
91
private boolean createFile (String path ) {
78
92
if (isAValidePath (path )) {
79
93
try {
94
+ // int actionToDo = 3;
95
+ // int currentAction = 0;
96
+ // setDownloadingValue(currentAction++ / (double) actionToDo);
97
+ // setDownloadingMessage("Creating file object for " + path);
80
98
File file = new File (path );
99
+ // setDownloadingValue(currentAction++ / (double) actionToDo);
100
+ // setDownloadingMessage("Creating parents");
81
101
createParents (file );
82
- return file .createNewFile ();
102
+ // setDownloadingValue(currentAction++ / (double) actionToDo);
103
+ // setDownloadingMessage("Creating file");
104
+ boolean r = file .createNewFile ();
105
+ // setDownloadingValue(currentAction++ / (double) actionToDo);
106
+ return r ;
83
107
} catch (IOException e ) {
84
108
return false ;
85
109
}
@@ -349,64 +373,64 @@ private boolean download(String url, String destination) {
349
373
return false ;
350
374
}
351
375
}
352
- }
353
-
354
- class FLUProgressionThread extends Thread {
355
- private File fileOut ;
356
- private long fileToDowloadSize ;
357
- private boolean running ;
358
- private String downloadName ;
359
- private FLUProgression progressionInstance ;
360
- /**
361
- * {@summary Main constructor.}<br>
362
- *
363
- * @param fileOut file that we are curently filling by the downloading file
364
- * @param fileToDowloadSize size that we should reach when download will end
365
- */
366
- public FLUProgressionThread (File fileOut , long fileToDowloadSize , String downloadName , FLUProgression progressionInstance ) {
367
- this .fileOut = fileOut ;
368
- this .fileToDowloadSize = fileToDowloadSize ;
369
- this .downloadName = downloadName ;
370
- this .progressionInstance = progressionInstance ;
371
- running = true ;
372
- }
376
+ class FLUProgressionThread extends Thread {
377
+ private File fileOut ;
378
+ private long fileToDowloadSize ;
379
+ private boolean running ;
380
+ private String downloadName ;
381
+ private FLUProgression progressionInstance ;
382
+ /**
383
+ * {@summary Main constructor.}<br>
384
+ *
385
+ * @param fileOut file that we are curently filling by the downloading file
386
+ * @param fileToDowloadSize size that we should reach when download will end
387
+ */
388
+ public FLUProgressionThread (File fileOut , long fileToDowloadSize , String downloadName , FLUProgression progressionInstance ) {
389
+ this .fileOut = fileOut ;
390
+ this .fileToDowloadSize = fileToDowloadSize ;
391
+ this .downloadName = downloadName ;
392
+ this .progressionInstance = progressionInstance ;
393
+ running = true ;
394
+ }
373
395
374
- public void stopRuning () { running = false ; }
375
- /**
376
- * {@summary Main function that print every second %age of download done.}<br>
377
- */
378
- public void run () {
379
- long fileOutSize = 0 ;
380
- long lastFileOutSize = 0 ;
381
- long timeStart = System .currentTimeMillis ();
382
- long timeFromLastBitDownload = timeStart ;
383
- while (fileOutSize < fileToDowloadSize && running ) {
384
- fileOutSize = fileOut .length ();
385
- double progression = ((double ) fileOutSize ) / (double ) fileToDowloadSize ;
386
- int percent = (int ) (100 * progression );
387
- long curentTime = System .currentTimeMillis ();
388
- long timeElapsed = curentTime - timeStart ;
389
- long timeLeft = (long ) ((double ) ((timeElapsed / progression ) - timeElapsed ));
390
- String sTimeLeft = FLUTime .msToTime (timeLeft ) + " left" ;
391
- String message = "Downloading " + downloadName + " - " + percent + "% - " ;
392
- if (fileOutSize != lastFileOutSize ) {// update watcher of working download
393
- timeFromLastBitDownload = curentTime ;
394
- }
395
- if (timeFromLastBitDownload + 10000 < curentTime ) {
396
- message += (((curentTime - timeFromLastBitDownload ) / 1000 ) + "s untill a new bit haven't been download" );
397
- if (timeFromLastBitDownload + 60000 < curentTime ) {
398
- stopRuning ();
399
- // TODO stop the IO opperation.
396
+ public void stopRuning () { running = false ; }
397
+ /**
398
+ * {@summary Main function that print every second %age of download done.}<br>
399
+ */
400
+ public void run () {
401
+ long fileOutSize = 0 ;
402
+ long lastFileOutSize = 0 ;
403
+ long timeStart = System .currentTimeMillis ();
404
+ long timeFromLastBitDownload = timeStart ;
405
+ while (fileOutSize < fileToDowloadSize && running ) {
406
+ fileOutSize = fileOut .length ();
407
+ double progression = ((double ) fileOutSize ) / (double ) fileToDowloadSize ;
408
+ int percent = (int ) (100 * progression );
409
+ long curentTime = System .currentTimeMillis ();
410
+ long timeElapsed = curentTime - timeStart ;
411
+ long timeLeft = (long ) ((double ) ((timeElapsed / progression ) - timeElapsed ));
412
+ String sTimeLeft = FLUTime .msToTime (timeLeft ) + " left" ;
413
+ String message = "Downloading " + downloadName + " - " + percent + "% - " ;
414
+ if (fileOutSize != lastFileOutSize ) {// update watcher of working download
415
+ timeFromLastBitDownload = curentTime ;
400
416
}
401
- } else {
402
- message += sTimeLeft ;
403
- }
404
- progressionInstance .setDownloadingValue (percent );
405
- progressionInstance .setDownloadingMessage (message );
417
+ if (timeFromLastBitDownload + 10000 < curentTime ) {
418
+ message += (((curentTime - timeFromLastBitDownload ) / 1000 ) + "s untill a new bit haven't been download" );
419
+ if (timeFromLastBitDownload + 60000 < curentTime ) {
420
+ stopRuning ();
421
+ // TODO stop the IO opperation.
422
+ }
423
+ } else {
424
+ message += sTimeLeft ;
425
+ }
426
+ progressionInstance .setDownloadingValue (percent );
427
+ progressionInstance .setDownloadingMessage (message );
406
428
407
- lastFileOutSize = fileOutSize ;
408
- FLUTime .sleep (50 );
429
+ lastFileOutSize = fileOutSize ;
430
+ FLUTime .sleep (50 );
431
+ }
409
432
}
410
433
}
411
434
}
435
+
412
436
}
0 commit comments