private void processFile ( Script s , File file ) throws IOException { if ( ! file . exists ( ) ) throw new FileNotFoundException ( file . getName ( ) ) ; if ( ! editFiles ) { try ( BufferedReader reader = new BufferedReader ( new FileReader ( file ) ) ) { PrintWriter writer = new PrintWriter ( System . out ) ; processReader ( s , reader , writer ) ; writer . flush ( ) ; } } else { File backup ; if ( backupExtension == null ) { backup = File . createTempFile ( "groovy_" , ".tmp" ) ; backup . deleteOnExit ( ) ; } else { backup = new File ( file . getPath ( ) + backupExtension ) ; } backup . delete ( ) ; if ( ! file . renameTo ( backup ) ) throw new IOException ( "unable to rename " + file + " to " + backup ) ; try ( BufferedReader reader = new BufferedReader ( new FileReader ( backup ) ) ; PrintWriter writer = new PrintWriter ( new FileWriter ( file ) ) ) { processReader ( s , reader , writer ) ; } } }
Process a single input file .