Author: rfelden
Date: Thu Jun 7 17:27:22 2007
New Revision: 54
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D54&repname=3D=
jahia_upgrade
Log:
linecounter minor update (now supports any number of files/directories as a=
rguments)
Modified:
trunk/linecounter/src/main/java/linecounter/LineCounter.java
Modified: trunk/linecounter/src/main/java/linecounter/LineCounter.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/linecounter/src=
/main/java/linecounter/LineCounter.java&rev=3D54&repname=3Djahia_upgrade
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/linecounter/src/main/java/linecounter/LineCounter.java (original)
+++ trunk/linecounter/src/main/java/linecounter/LineCounter.java Thu Jun 7=
17:27:22 2007
@@ -11,26 +11,29 @@
*/
public class LineCounter {
public static void main(String[] args) {
- if (args.length !=3D 1) {
- System.err.println("Please provide only a file name/path as ar=
guments.") ;
- }
- File file =3D new File(args[0]) ;
- if (!file.exists()) {
- System.err.println("This is not a valid file name, retry using=
the absolute path.") ;
- } else {
- try {
- long time =3D System.currentTimeMillis() ;
- long lines =3D countLinesRec(file) ;
- System.out.println("\n\nThis contains " + lines + " lines\=
n") ;
- System.out.println("(calculated in " + (System.currentTime=
Millis() - time) + " ms)") ;
- } catch (IOException e) {
- System.err.println("\nAn error occurred!") ;
- e.printStackTrace() ;
+ long total =3D 0 ;
+ for (int i =3D 0; i < args.length; i++) {
+ File file =3D new File(args[i]) ;
+ if (!file.exists()) {
+ System.err.println("This is not a valid file name, retry u=
sing the absolute path.") ;
+ } else {
+ try {
+ long time =3D System.currentTimeMillis() ;
+ System.out.println("\nAnalyzing "+file.getAbsolutePath=
()) ;
+ long lines =3D countLinesRec(file, false) ;
+ total +=3D lines ;
+ System.out.println("\nThis contains " + lines + " line=
s") ;
+ System.out.println("(calculated in " + (System.current=
TimeMillis() - time) + " ms)") ;
+ } catch (IOException e) {
+ System.err.println("\nAn error occurred!") ;
+ e.printStackTrace() ;
+ }
}
}
+ System.out.println("\n\nThere are " + total + " lines in all these=
files/folders.") ;
}
=
- public static long countLinesRec(File file) throws IOException {
+ public static long countLinesRec(File file, boolean includeBlank) thro=
ws IOException {
if (file =3D=3D null) {
return 0L ;
} else if (file.isFile()) {
@@ -39,7 +42,7 @@
long lineCount =3D 0 ;
String read ;
while ((read =3D reader.readLine()) !=3D null) {
- if (!read.trim().equals("")) {
+ if (!read.trim().equals("") || includeBlank) {
lineCount++ ;
}
}
@@ -48,7 +51,7 @@
File[] files =3D file.listFiles() ;
long lineCount =3D 0 ;
for (File f : files) {
- lineCount +=3D countLinesRec(f) ;
+ lineCount +=3D countLinesRec(f, includeBlank) ;
}
return lineCount ;
} else {
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list