Changeset 16532 for release-kits/shared


Ignore:
Timestamp:
2008-07-24T13:20:48+12:00 (16 years ago)
Author:
oranfry
Message:

made the rsr task safer

Location:
release-kits/shared/ant-tasks/orans
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release-kits/shared/ant-tasks/orans/RegexSearchReplace.java

    r15090 r16532  
    1616     */
    1717    public static void main( String[] args ) {
     18
    1819        RegexSearchReplace rsr = new RegexSearchReplace();
    1920        rsr.setFile(new File (args[0]));
     
    3637
    3738        if (replacement == null) {
    38             replacement = "";
     39            throw new BuildException( "Error - No replacement specified !!" );
    3940        }
    4041
     
    4445        File temp = null;
    4546        try {
    46             // Create temp file.
     47            //create temp file.
    4748            temp = File.createTempFile("rsr", ".tmp");
    4849
    49             // Delete temp file when program exits.
     50            //delete temp file when program exits.
    5051            temp.deleteOnExit();
    5152
    52             // Write to temp file
     53            //writer to temp file
    5354            out = new BufferedWriter(new FileWriter(temp));
    5455
    55         } catch (IOException e) {}
     56        } catch (IOException e) {
     57            throw new BuildException( "Error - Couldn't create the temp file" );
     58        }
    5659
    5760
     
    6063        try {
    6164            in = new BufferedReader(new FileReader( file ));
    62         } catch ( Exception e ) {}
     65        } catch ( Exception e ) {
     66            throw new BuildException( "Error - Couldn't open the specified file" );
     67        }
    6368
    6469        //pass the file through, searching and replacing
     
    7075                out.newLine();
    7176            }
     77        } catch ( Exception e ) {
     78            throw new BuildException( "Error - Couldn't read from the specified file" );
     79        }
     80
     81        try {
     82
    7283            //close them both up
    7384            in.close();
     
    7586
    7687        } catch ( Exception e ) {
    77             e.printStackTrace();
     88            throw new BuildException( "Error - Couldn't close a file" );
    7889        }
    7990
    8091
     92        //copy the new file (temp) over the original
     93        InputStream i;
     94        OutputStream o;
     95        try {
     96            i = new FileInputStream(temp);
     97            o = new FileOutputStream(file);
    8198
    82         //copy the new file (temp) over the original
     99        } catch ( Exception e ) {
     100            throw new BuildException( "Error - Couldn't open the temp file" );
     101        }
     102
    83103        try {
    84             InputStream i = new FileInputStream(temp);
    85             OutputStream o = new FileOutputStream(file);
    86 
     104   
    87105            // Transfer bytes from in to out
    88106            byte[] buf = new byte[1024];
     
    95113            i.close();
    96114            o.close();
    97         } catch ( Exception e ) {}
     115        } catch ( Exception e ) {
     116            throw new BuildException( "Error - Couldn't write to the specified file" );
     117        }
    98118       
    99119    }
Note: See TracChangeset for help on using the changeset viewer.