- Timestamp:
- 2008-07-24T13:20:48+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
release-kits/shared/ant-tasks/orans/RegexSearchReplace.java
r15090 r16532 16 16 */ 17 17 public static void main( String[] args ) { 18 18 19 RegexSearchReplace rsr = new RegexSearchReplace(); 19 20 rsr.setFile(new File (args[0])); … … 36 37 37 38 if (replacement == null) { 38 replacement = "";39 throw new BuildException( "Error - No replacement specified !!" ); 39 40 } 40 41 … … 44 45 File temp = null; 45 46 try { 46 // Create temp file.47 //create temp file. 47 48 temp = File.createTempFile("rsr", ".tmp"); 48 49 49 // Delete temp file when program exits.50 //delete temp file when program exits. 50 51 temp.deleteOnExit(); 51 52 52 // Writeto temp file53 //writer to temp file 53 54 out = new BufferedWriter(new FileWriter(temp)); 54 55 55 } catch (IOException e) {} 56 } catch (IOException e) { 57 throw new BuildException( "Error - Couldn't create the temp file" ); 58 } 56 59 57 60 … … 60 63 try { 61 64 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 } 63 68 64 69 //pass the file through, searching and replacing … … 70 75 out.newLine(); 71 76 } 77 } catch ( Exception e ) { 78 throw new BuildException( "Error - Couldn't read from the specified file" ); 79 } 80 81 try { 82 72 83 //close them both up 73 84 in.close(); … … 75 86 76 87 } catch ( Exception e ) { 77 e.printStackTrace();88 throw new BuildException( "Error - Couldn't close a file" ); 78 89 } 79 90 80 91 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); 81 98 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 83 103 try { 84 InputStream i = new FileInputStream(temp); 85 OutputStream o = new FileOutputStream(file); 86 104 87 105 // Transfer bytes from in to out 88 106 byte[] buf = new byte[1024]; … … 95 113 i.close(); 96 114 o.close(); 97 } catch ( Exception e ) {} 115 } catch ( Exception e ) { 116 throw new BuildException( "Error - Couldn't write to the specified file" ); 117 } 98 118 99 119 }
Note:
See TracChangeset
for help on using the changeset viewer.