@@ -75,7 +75,7 @@ HashSet<String> copyFolders(File dir, File outputDir, PrintStream output,
7575
7676 Map <String , Object > metadata = parseMetadata (dir );
7777 HashSet <String > failed = new HashSet <>();
78- AtomicInteger index = new AtomicInteger (1 );
78+ AtomicInteger index = new AtomicInteger (0 );
7979 int size = metadata .size ();
8080
8181 getSubmissionsStreamByDate (metadata ).forEach ((entry ) -> {
@@ -87,11 +87,8 @@ HashSet<String> copyFolders(File dir, File outputDir, PrintStream output,
8787 String name = getSubmissionName (userData , entry .getKey (), output );
8888 String sid = getStudentId (userData , output );
8989 String id = getSubmissionId (entry .getKey (), output );
90-
91- String outputDirRelative = String .format ("%d_of_%d" , index .getAndIncrement (), size );
92- if (!isAnonymous ) {
93- outputDirRelative += String .format ("_%s_%s" , sid , name ).replaceAll ("[^a-zA-Z0-9_\\ -]" , "_" );
94- }
90+ String outputDirRelative =
91+ generateOutputDirName (index .incrementAndGet (), size , id , sid , name );
9592
9693 if (!performCopy (dir , outputDirRelative , id , name , outputDir , copier , output , failed )) {
9794 return ;
@@ -202,6 +199,16 @@ private String getSubmissionId(String id, PrintStream output) {
202199 }
203200 }
204201
202+ private String generateOutputDirName (int index , int size , String submissionId , String sid ,
203+ String name ) {
204+ StringBuilder outputDir = new StringBuilder ();
205+ outputDir .append (index ).append ("_of_" ).append (size ).append ('_' ).append (submissionId );
206+ if (!isAnonymous ) {
207+ outputDir .append ('_' ).append (sid ).append ('_' ).append (name );
208+ }
209+ return outputDir .toString ().replaceAll ("[^a-zA-Z0-9_\\ -]" , "_" ).replaceAll ("_+" , "_" );
210+ }
211+
205212 private boolean performCopy (File dir , String outputDirRelative , String id , String name ,
206213 File outputDir , OutputDirectoryHandler copier , PrintStream output , HashSet <String > failed ) {
207214 Path inputDir = new File (dir , String .format (OUTPUT_DIR_FORMAT , id )).toPath ();
0 commit comments