public static void convertFile ( File original ) throws IOException { File outputFile = determineClassName ( original ) ; String classNameOld = className ( original ) ; String classNameNew = className ( outputFile ) ; // Read the file and split it up into lines List < String > inputLines = FileUtils . readLines ( original , "UTF-8" ) ; List < String > outputLines = new ArrayList <> ( ) ; List < Macro > macros = new ArrayList <> ( ) ; // parse each line by line looking for instructions boolean foundClassDef = false ; for ( int i = 0 ; i < inputLines . size ( ) ; i ++ ) { String line = inputLines . get ( i ) ; int where = line . indexOf ( prefix ) ; if ( where < 0 ) { if ( ! foundClassDef && line . contains ( "class " + classNameOld ) ) { foundClassDef = true ; line = line . replaceFirst ( "class " + classNameOld , "class " + classNameNew ) ; } else { line = line . replace ( classNameOld + "(" , classNameNew + "(" ) ; } outputLines . add ( line ) ; continue ; } String type = readType ( line , where + prefix . length ( ) ) ; String whitespaces = line . substring ( 0 , where ) ; int frontLength = where + prefix . length ( ) + type . length ( ) ; String message = line . length ( ) > frontLength ? line . substring ( frontLength + 1 ) : "" ; switch ( type ) { case "CLASS_NAME" : continue ; // ignore. already processed case "INLINE" : outputLines . add ( whitespaces + message ) ; break ; case "ABOVE" : // remove the previous line outputLines . remove ( outputLines . size ( ) - 1 ) ; outputLines . add ( whitespaces + message ) ; break ; case "BELOW" : outputLines . add ( whitespaces + message ) ; i += 1 ; // skip next line break ; case "REMOVE_ABOVE" : outputLines . remove ( outputLines . size ( ) - 1 ) ; break ; case "REMOVE_BELOW" : i += 1 ; // skip next line break ; case "MACRO" : throw new RuntimeException ( "MACRO not handled yet" ) ; default : throw new RuntimeException ( "Unknown: " + type ) ; } } PrintStream out = new PrintStream ( outputFile ) ; for ( int i = 0 ; i < outputLines . size ( ) ; i ++ ) { out . println ( outputLines . get ( i ) ) ; } out . close ( ) ; createTestIfNotThere ( outputFile ) ; }
Converts the file from single thread into concurrent implementation