22
33import java .io .File ;
44import java .io .FileInputStream ;
5- import java .io .FileNotFoundException ;
65import java .io .IOException ;
76import java .nio .file .Files ;
87import java .nio .file .Paths ;
1514public class App {
1615 private static String VERSION = "1.0.0" ;
1716 private static String APP_NAME = "Validate PDF Accessibility" ;
17+ private static String OP_DUPLICATE_MCID = "OP_DUPLICATE_MCID" ;
1818
19- private static void displayVersion () {
20- Properties properties = new Properties ();
21- try {
22- properties .load (App .class .getClassLoader ().getResourceAsStream ("version.properties" ));
23- VERSION = properties .getProperty ("project.version" );
24- APP_NAME = properties .getProperty ("project.name" );
25- System .out .println (APP_NAME + " v" + VERSION + "\n " );
26- } catch (IOException e ) {
27- System .err .println ("Error reading version information." );
28- }
29- }
3019
3120 public static boolean isPDFFile (String filePath ) {
3221 File file = new File (filePath );
@@ -53,39 +42,6 @@ public static boolean isPDFFile(String filePath) {
5342 }
5443 }
5544
56- // Collects all files from the specified directory
57- private static List <File > collectFiles (String directoryPath ) {
58- List <File > fileList = new ArrayList <>();
59- try {
60- Files .walk (Paths .get (directoryPath ))
61- .filter (Files ::isRegularFile ) // Include only regular files (not directories)
62- .forEach (path -> fileList .add (path .toFile ()));
63- } catch (IOException e ) {
64- System .err .println ("Error reading files: " + e .getMessage ());
65- }
66- return fileList ;
67- }
68-
69- private static int processFile (File file ) throws Exception {
70- // Process single file
71- System .out .println ("File: " + file .getPath () + "" );
72-
73- if (!isPDFFile (file .getAbsolutePath ())) {
74- System .out .println ("Not a PDF file" );
75- return 0 ;
76- }
77-
78- int count = FindDuplicateMcid .checkDuplicateMcid (file .getAbsolutePath ());
79- if (count == 0 ) {
80- System .out .println ("No duplicate MCIDs found" );
81- } else {
82- System .out .println (String .format ("Total %d duplicate MCID(s) found" , count ));
83- }
84- return count ;
85- }
86-
87- private static String OP_DUPLICATE_MCID = "OP_DUPLICATE_MCID" ;
88-
8945 public static void main (String [] args ) throws Exception {
9046 displayVersion ();
9147
@@ -94,7 +50,11 @@ public static void main(String[] args) throws Exception {
9450 String last = "" ;
9551
9652 String op = "" ;
53+
54+ ConsoleProgressBar progressBar = null ;
55+
9756 try {
57+ // Parse arguments
9858 for (String s : args ) {
9959 if (last .isEmpty ()) {
10060 if (s .equals ("--help" )) {
@@ -132,6 +92,8 @@ public static void main(String[] args) throws Exception {
13292 throw new RuntimeException ("Missing operation argument. See --help" );
13393 }
13494
95+ progressBar = new ConsoleProgressBar ("Gathering files" );
96+
13597 List <File > fileList = new ArrayList <>();
13698 if (!inputFile .isEmpty ()) {
13799 fileList .add (new File (inputFile ));
@@ -154,6 +116,10 @@ public int compare(File f1, File f2) {
154116 }
155117 });
156118
119+ progressBar .update (10f );
120+ progressBar .setTitle ("Processing files" );
121+ float step = fileList .size () / 90f ;
122+
157123 int count = 0 ;
158124
159125 // Process each file
@@ -167,13 +133,68 @@ public int compare(File f1, File f2) {
167133 System .err .println (e .getLocalizedMessage ());
168134 }
169135 System .out .println ("===============================================================================\n " );
136+ progressBar .update (step );
170137 }
171138 System .out .println ("Process complete" );
139+
140+ progressBar .setProgress (100f );
141+ progressBar .setTitle ("Done" );
142+ progressBar .waitUntilFinished ();
143+
172144 System .exit (Math .min (count , ExitCodes .MAX_SUCCESS ));
173145 } catch (Exception e ) {
146+ if ((progressBar != null ) && progressBar .isRunning ()) {
147+ progressBar .stop ();
148+ }
149+
174150 System .err .println (ExitCodes .GENERAL_MESSAGE );
175151 System .err .println (e .getLocalizedMessage ());
176152 System .exit (ExitCodes .GENERAL_ERROR );
177153 }
154+
155+ }
156+
157+
158+ private static void displayVersion () {
159+ Properties properties = new Properties ();
160+ try {
161+ properties .load (App .class .getClassLoader ().getResourceAsStream ("version.properties" ));
162+ VERSION = properties .getProperty ("project.version" );
163+ APP_NAME = properties .getProperty ("project.name" );
164+ System .out .println (APP_NAME + " v" + VERSION + "\n " );
165+ } catch (IOException e ) {
166+ System .err .println ("Error reading version information." );
167+ }
168+ }
169+
170+ // Collects all files from the specified directory
171+ private static List <File > collectFiles (String directoryPath ) {
172+ List <File > fileList = new ArrayList <>();
173+ try {
174+ Files .walk (Paths .get (directoryPath ))
175+ .filter (Files ::isRegularFile ) // Include only regular files (not directories)
176+ .forEach (path -> fileList .add (path .toFile ()));
177+ } catch (IOException e ) {
178+ System .err .println ("Error reading files: " + e .getMessage ());
179+ }
180+ return fileList ;
181+ }
182+
183+ private static int processFile (File file ) throws Exception {
184+ // Process single file
185+ System .out .println ("File: " + file .getPath () + "" );
186+
187+ if (!isPDFFile (file .getAbsolutePath ())) {
188+ System .out .println ("Not a PDF file" );
189+ return 0 ;
190+ }
191+
192+ int count = FindDuplicateMcid .checkDuplicateMcid (file .getAbsolutePath ());
193+ if (count == 0 ) {
194+ System .out .println ("No duplicate MCIDs found" );
195+ } else {
196+ System .out .println (String .format ("Total %d duplicate MCID(s) found" , count ));
197+ }
198+ return count ;
178199 }
179200}
0 commit comments