diff options
author | Tomas O'Connor <toconnor@openoffice.org> | 2003-06-12 10:28:18 +0000 |
---|---|---|
committer | Tomas O'Connor <toconnor@openoffice.org> | 2003-06-12 10:28:18 +0000 |
commit | 6b973771a118074dfd1e892467df489389274edf (patch) | |
tree | b59b6b3a0215321bdb9fc6fb0969964ce361dcfb /scripting/java/org/openoffice/netbeans/modules/office/utils | |
parent | INTEGRATION: CWS mh11rc (1.5.132); FILE MERGED (diff) | |
download | core-6b973771a118074dfd1e892467df489389274edf.tar.gz core-6b973771a118074dfd1e892467df489389274edf.zip |
Ensure that IO streams are closed before returning, cleanup unneeded code
Diffstat (limited to 'scripting/java/org/openoffice/netbeans/modules/office/utils')
-rw-r--r-- | scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java b/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java index 49ce1cba1a92..7b39fcdd6ba2 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java @@ -2,9 +2,9 @@ * * $RCSfile: PackageRemover.java,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: toconnor $ $Date: 2003-02-06 18:23:12 $ + * last change: $Author: toconnor $ $Date: 2003-06-12 11:28:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -80,35 +80,38 @@ public class PackageRemover { BufferedReader in = new BufferedReader(new FileReader(source)); BufferedWriter out = new BufferedWriter(new FileWriter(tmp)); - String line; - while ((line = in.readLine()) != null) { - if (line.startsWith("package")) { - String newDeclaration = evaluate(line); - if (newDeclaration != null) { - out.write(newDeclaration, 0, newDeclaration.length()); + try { + String line; + while ((line = in.readLine()) != null) { + if (line.startsWith("package")) { + String newDeclaration = evaluate(line); + if (newDeclaration != null) { + out.write(newDeclaration, 0, newDeclaration.length()); + out.newLine(); + } + } + else { + out.write(line, 0, line.length()); out.newLine(); } } - else { - out.write(line, 0, line.length()); - out.newLine(); - } } - - while ((line = in.readLine()) != null) { - out.write(line, 0, line.length()); - out.newLine(); + finally { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } } - in.close(); - out.close(); - if (source.delete() == false) { tmp.delete(); throw new IOException("Could not overwrite " + source); } - else + else { tmp.renameTo(source); + } } public static String evaluate(String line) { |