@@ -63,7 +63,6 @@ static public byte[] loadBytesRaw(File file) throws IOException {
63
63
if (bytesRead == 0 ) break ;
64
64
}
65
65
input .close (); // weren't properly being closed
66
- input = null ;
67
66
return buffer ;
68
67
}
69
68
@@ -79,7 +78,7 @@ static public StringDict readSettings(File inputFile) {
79
78
Messages .err (inputFile + " does not exist inside readSettings()" );
80
79
return null ;
81
80
}
82
- String lines [] = PApplet .loadStrings (inputFile );
81
+ String [] lines = PApplet .loadStrings (inputFile );
83
82
if (lines == null ) {
84
83
System .err .println ("Could not read " + inputFile );
85
84
return null ;
@@ -138,11 +137,9 @@ static public void copyFile(File sourceFile,
138
137
to .write (buffer , 0 , bytesRead );
139
138
}
140
139
from .close ();
141
- from = null ;
142
140
143
141
to .flush ();
144
142
to .close ();
145
- to = null ;
146
143
147
144
targetFile .setLastModified (sourceFile .lastModified ());
148
145
targetFile .setExecutable (sourceFile .canExecute ());
@@ -172,9 +169,8 @@ static public void saveFile(String text, File file) throws IOException {
172
169
File temp = File .createTempFile (file .getName (), null , file .getParentFile ());
173
170
try {
174
171
// fix from cjwant to prevent symlinks from being destroyed.
175
- File canon = file .getCanonicalFile ();
176
- // assign the var as second step since previous line may throw exception
177
- file = canon ;
172
+ file = file .getCanonicalFile ();
173
+
178
174
} catch (IOException e ) {
179
175
throw new IOException ("Could not resolve canonical representation of " +
180
176
file .getAbsolutePath ());
@@ -242,27 +238,27 @@ static public void copyDir(File sourceDir,
242
238
throw new IllegalArgumentException (urDum );
243
239
}
244
240
targetDir .mkdirs ();
245
- String files [] = sourceDir .list ();
246
- for (int i = 0 ; i < files . length ; i ++ ) {
241
+ String [] filenames = sourceDir .list ();
242
+ for (String filename : filenames ) {
247
243
// Ignore dot files (.DS_Store), dot folders (.svn) while copying
248
- if (files [ i ] .charAt (0 ) == '.' ) continue ;
249
- //if (files[i].equals(".") || files[i].equals("..")) continue ;
250
- File source = new File (sourceDir , files [ i ] );
251
- File target = new File ( targetDir , files [ i ]);
252
- if ( source . isDirectory ()) {
253
- //target.mkdirs( );
254
- copyDir ( source , target );
255
- target . setLastModified ( source . lastModified ());
256
- } else {
257
- copyFile ( source , target );
244
+ if (filename .charAt (0 ) != '.' ) {
245
+ File source = new File ( sourceDir , filename ) ;
246
+ File target = new File (targetDir , filename );
247
+ if ( source . isDirectory ()) {
248
+ //target.mkdirs();
249
+ copyDir ( source , target );
250
+ target . setLastModified ( source . lastModified () );
251
+ } else {
252
+ copyFile ( source , target );
253
+ }
258
254
}
259
255
}
260
256
}
261
257
262
258
263
259
static public void copyDirNative (File sourceDir ,
264
260
File targetDir ) throws IOException {
265
- Process process = null ;
261
+ Process process ;
266
262
if (Platform .isMacOS () || Platform .isLinux ()) {
267
263
process = Runtime .getRuntime ().exec (new String [] {
268
264
"cp" , "-a" , sourceDir .getAbsolutePath (), targetDir .getAbsolutePath ()
@@ -363,21 +359,25 @@ static public long calcSize(File file) {
363
359
* Note that the function calls itself recursively.
364
360
*/
365
361
static public long calcFolderSize (File folder ) {
366
- int size = 0 ;
362
+ long size = 0 ;
367
363
368
- String files [] = folder .list ();
364
+ String [] filenames = folder .list ();
369
365
// null if folder doesn't exist, happens when deleting sketch
370
- if (files == null ) return -1 ;
371
-
372
- for (int i = 0 ; i < files .length ; i ++) {
373
- if (files [i ].equals ("." ) ||
374
- files [i ].equals (".." ) ||
375
- files [i ].equals (".DS_Store" )) continue ;
376
- File fella = new File (folder , files [i ]);
377
- if (fella .isDirectory ()) {
378
- size += calcFolderSize (fella );
379
- } else {
380
- size += (int ) fella .length ();
366
+ if (filenames == null ) return -1 ;
367
+
368
+ for (String file : filenames ) {
369
+ if (!file .equals ("." ) && !file .equals (".." ) && !file .equals (".DS_Store" )) {
370
+ File fella = new File (folder , file );
371
+ if (fella .isDirectory ()) {
372
+ long subfolderSize = calcFolderSize (fella );
373
+ if (subfolderSize == -1 ) {
374
+ return -1 ;
375
+ } else {
376
+ size += subfolderSize ;
377
+ }
378
+ } else {
379
+ size += fella .length ();
380
+ }
381
381
}
382
382
}
383
383
return size ;
@@ -445,13 +445,10 @@ static void listFilesImpl(File folder, boolean relative,
445
445
* @return a list of .jar and .zip files in that folder
446
446
*/
447
447
static public File [] listJarFiles (File folder ) {
448
- return folder .listFiles (new FilenameFilter () {
449
- public boolean accept (File dir , String name ) {
450
- return (!name .startsWith ("." ) &&
451
- (name .toLowerCase ().endsWith (".jar" ) ||
452
- name .toLowerCase ().endsWith (".zip" )));
453
- }
454
- });
448
+ return folder .listFiles ((dir , name ) ->
449
+ (!name .startsWith ("." ) &&
450
+ (name .toLowerCase ().endsWith (".jar" ) ||
451
+ name .toLowerCase ().endsWith (".zip" ))));
455
452
}
456
453
457
454
@@ -485,17 +482,17 @@ static public String contentsToClassPath(File folder) {
485
482
path += File .separator ;
486
483
}
487
484
488
- String list [] = folder .list ();
489
- for (int i = 0 ; i < list . length ; i ++ ) {
485
+ String [] list = folder .list ();
486
+ for (String item : list ) {
490
487
// Skip . and ._ files. Prior to 0125p3, .jar files that had
491
488
// OS X AppleDouble files associated would cause trouble.
492
- if (list [ i ] .startsWith ("." )) continue ;
493
-
494
- if ( list [ i ] .toLowerCase ().endsWith (".jar" ) ||
495
- list [ i ]. toLowerCase (). endsWith ( ".zip" )) {
496
- sb .append (sep );
497
- sb .append (path );
498
- sb . append ( list [ i ]);
489
+ if (! item .startsWith ("." )) {
490
+ if ( item . toLowerCase (). endsWith ( ".jar" ) ||
491
+ item .toLowerCase ().endsWith (".zip" )) {
492
+ sb . append ( sep );
493
+ sb .append (path );
494
+ sb .append (item );
495
+ }
499
496
}
500
497
}
501
498
} catch (IOException e ) {
@@ -516,25 +513,25 @@ static public String contentsToClassPath(File folder) {
516
513
static public StringList packageListFromClassPath (String path ) {
517
514
// Map<String, Object> map = new HashMap<String, Object>();
518
515
StringList list = new StringList ();
519
- String pieces [] =
516
+ String [] pieces =
520
517
PApplet .split (path , File .pathSeparatorChar );
521
518
522
- for (int i = 0 ; i < pieces . length ; i ++ ) {
519
+ for (String piece : pieces ) {
523
520
//System.out.println("checking piece '" + pieces[i] + "'");
524
- if (pieces [ i ] .length () == 0 ) continue ;
525
-
526
- if ( pieces [ i ] .toLowerCase ().endsWith (".jar" ) ||
527
- pieces [ i ]. toLowerCase (). endsWith ( ".zip" )) {
528
- //System.out.println("checking " + pieces[i] );
529
- packageListFromZip ( pieces [ i ], list );
530
-
531
- } else { // it's another type of file or directory
532
- File dir = new File ( pieces [ i ]);
533
- if (dir . exists () && dir . isDirectory ()) {
534
- packageListFromFolder (dir , null , list );
535
- //importCount = magicImportsRecursive(dir, null,
536
- // map );
537
- //imports, importCount);
521
+ if (piece .length () != 0 ) {
522
+ if ( piece . toLowerCase (). endsWith ( ".jar" ) ||
523
+ piece .toLowerCase ().endsWith (".zip" )) {
524
+ //System.out.println("checking " + pieces[i]);
525
+ packageListFromZip ( piece , list );
526
+
527
+ } else { // it's another type of file or directory
528
+ File dir = new File ( piece );
529
+ if ( dir . exists () && dir . isDirectory ()) {
530
+ packageListFromFolder (dir , null , list );
531
+ //importCount = magicImportsRecursive (dir, null,
532
+ // map);
533
+ //imports, importCount );
534
+ }
538
535
}
539
536
}
540
537
}
@@ -593,24 +590,18 @@ static private void packageListFromFolder(File dir, String sofar,
593
590
StringList list ) {
594
591
// Map<String, Object> map) {
595
592
boolean foundClass = false ;
596
- String files [] = dir .list ();
593
+ String [] filenames = dir .list ();
597
594
598
- for (int i = 0 ; i < files . length ; i ++ ) {
599
- if (files [ i ] .equals ("." ) || files [ i ] .equals (".." )) continue ;
595
+ for (String filename : filenames ) {
596
+ if (filename .equals ("." ) || filename .equals (".." )) continue ;
600
597
601
- File sub = new File (dir , files [ i ] );
598
+ File sub = new File (dir , filename );
602
599
if (sub .isDirectory ()) {
603
600
String nowfar =
604
- (sofar == null ) ? files [ i ] : (sofar + "." + files [ i ] );
601
+ (sofar == null ) ? filename : (sofar + "." + filename );
605
602
packageListFromFolder (sub , nowfar , list );
606
- //System.out.println(nowfar);
607
- //imports[importCount++] = nowfar;
608
- //importCount = magicImportsRecursive(sub, nowfar,
609
- // imports, importCount);
610
603
} else if (!foundClass ) { // if no classes found in this folder yet
611
- if (files [i ].endsWith (".class" )) {
612
- //System.out.println("unique class: " + files[i] + " for " + sofar);
613
- // map.put(sofar, new Object());
604
+ if (filename .endsWith (".class" )) {
614
605
list .appendUnique (sofar );
615
606
foundClass = true ;
616
607
}
@@ -628,7 +619,7 @@ static public void unzip(File zipFile, File dest) {
628
619
FileInputStream fis = new FileInputStream (zipFile );
629
620
CheckedInputStream checksum = new CheckedInputStream (fis , new Adler32 ());
630
621
ZipInputStream zis = new ZipInputStream (new BufferedInputStream (checksum ));
631
- ZipEntry entry = null ;
622
+ ZipEntry entry ;
632
623
while ((entry = zis .getNextEntry ()) != null ) {
633
624
final String name = entry .getName ();
634
625
if (!name .startsWith (("__MACOSX" ))) {
@@ -655,7 +646,7 @@ static public void unzip(File zipFile, File dest) {
655
646
static protected void unzipEntry (ZipInputStream zin , File f ) throws IOException {
656
647
FileOutputStream out = new FileOutputStream (f );
657
648
byte [] b = new byte [512 ];
658
- int len = 0 ;
649
+ int len ;
659
650
while ((len = zin .read (b )) != -1 ) {
660
651
out .write (b , 0 , len );
661
652
}
0 commit comments