diff options
author | Noel Grandin <noel@peralex.com> | 2013-05-03 15:18:08 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2013-05-06 11:45:56 +0200 |
commit | 402c8f5f1efd053cc69556d63999955b3af4f41d (patch) | |
tree | 6f5dd611fa39962511feeaf1802d3776217f84fe /scripting | |
parent | 7cba598a7ddcf02771ed31c8d8fce6f7e02ef715 (diff) |
Java cleanup, close file handles when done with them
Change-Id: I79e6e0b8f53ae6f232c34aa8e833853d2ec24cf0
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/workben/installer/FileUpdater.java | 3 | ||||
-rw-r--r-- | scripting/workben/installer/InstUtil.java | 5 | ||||
-rw-r--r-- | scripting/workben/installer/ZipData.java | 68 | ||||
-rw-r--r-- | scripting/workben/mod/_scripting/TestDataLoader.java | 5 |
4 files changed, 40 insertions, 41 deletions
diff --git a/scripting/workben/installer/FileUpdater.java b/scripting/workben/installer/FileUpdater.java index 786b8f44bda8..21c3d34dd367 100644 --- a/scripting/workben/installer/FileUpdater.java +++ b/scripting/workben/installer/FileUpdater.java @@ -42,6 +42,7 @@ public class FileUpdater { s.trim(); xmlArray[count] = s; } + reader.close(); } catch( IOException ioe ) { String message = "\nError reading ProtocolHandler.xcu, please view SFrameworkInstall.log."; @@ -112,6 +113,7 @@ public class FileUpdater { s.trim(); xmlArray[count] = s; } + reader.close(); } catch( IOException ioe ) { String message = "Error reading script.xlc, please view SFrameworkInstall.log."; @@ -184,6 +186,7 @@ public class FileUpdater { s.trim(); xmlArray[count] = s; } + reader.close(); } catch( IOException ioe ) { diff --git a/scripting/workben/installer/InstUtil.java b/scripting/workben/installer/InstUtil.java index c6a713153e87..26ec2027b4d6 100644 --- a/scripting/workben/installer/InstUtil.java +++ b/scripting/workben/installer/InstUtil.java @@ -237,6 +237,7 @@ public class InstUtil { break; } } + reader.close(); } catch( IOException ioe ) { System.out.println( "Error reading Netbeans location information" ); @@ -285,6 +286,7 @@ public class InstUtil { jeditDetails[1] = version; } } + reader.close(); } catch( IOException ioe ) { System.out.println( "Error reading Jedit location information" ); @@ -292,7 +294,6 @@ public class InstUtil { //catch( FileNotFoundException fnfe ) { //System.out.println( "Jedit activity.log FileNotFoundException" ); //} - return jeditDetails; } @@ -408,7 +409,7 @@ public class InstUtil { } } } - + reader.close(); return results; } diff --git a/scripting/workben/installer/ZipData.java b/scripting/workben/installer/ZipData.java index 432201ff7e54..0cd144a7abfd 100644 --- a/scripting/workben/installer/ZipData.java +++ b/scripting/workben/installer/ZipData.java @@ -21,13 +21,12 @@ package installer; import java.io.*; import javax.swing.*; -public class ZipData -{ +public class ZipData { public ZipData(String file) { } public boolean extractEntry(String entry, String destination, - JLabel statusLabel) { + JLabel statusLabel) { OutputStream out = null; InputStream in = null; @@ -35,23 +34,22 @@ public class ZipData System.out.println("Copying: " + entry); System.out.println("To: " + destination); - if (statusLabel != null) { - statusLabel.setText("Copying " + entry); - } + if (statusLabel != null) { + statusLabel.setText("Copying " + entry); + } String entryName; if (entry.lastIndexOf("/") != -1) { entryName = entry.substring(entry.lastIndexOf("/") + 1); - } - else { + } else { entryName = entry; } String destName; if (destination.lastIndexOf(File.separator) != -1) { - destName = destination.substring(destination.lastIndexOf(File.separator) + 1); - } - else { + destName = destination.substring(destination + .lastIndexOf(File.separator) + 1); + } else { destName = destination; } @@ -60,20 +58,6 @@ public class ZipData System.out.println("Unzipping " + entry + " to " + destination); - try { - out = new FileOutputStream(destination); - } - catch (IOException ioe) { - System.err.println("Error opening " + destination + - ": " + ioe.getMessage()); - - if (statusLabel != null) - statusLabel.setText("Error opening" + destination + - "see SFramework.log for more information"); - - return false; - } - if (entry.startsWith("/") == false) entry = "/" + entry; @@ -82,8 +66,21 @@ public class ZipData System.err.println("File " + entry + " not found in jar file"); if (statusLabel != null) - statusLabel.setText("Failed extracting " + entry + - "see SFramework.log for more information"); + statusLabel.setText("Failed extracting " + entry + + "see SFramework.log for more information"); + + return false; + } + + try { + out = new FileOutputStream(destination); + } catch (IOException ioe) { + System.err.println("Error opening " + destination + ": " + + ioe.getMessage()); + + if (statusLabel != null) + statusLabel.setText("Error opening" + destination + + "see SFramework.log for more information"); return false; } @@ -94,22 +91,19 @@ public class ZipData while ((len = in.read(bytes)) != -1) out.write(bytes, 0, len); - } - catch (IOException ioe) { - System.err.println("Error writing " + destination + ": " + - ioe.getMessage()); + } catch (IOException ioe) { + System.err.println("Error writing " + destination + ": " + + ioe.getMessage()); if (statusLabel != null) - statusLabel.setText("Failed writing " + destination + - "see SFramework.log for more information"); + statusLabel.setText("Failed writing " + destination + + "see SFramework.log for more information"); return false; - } - finally { + } finally { try { in.close(); out.close(); - } - catch (IOException ioe) { + } catch (IOException ioe) { } } return true; diff --git a/scripting/workben/mod/_scripting/TestDataLoader.java b/scripting/workben/mod/_scripting/TestDataLoader.java index c76d4351aad5..63d360e6a678 100644 --- a/scripting/workben/mod/_scripting/TestDataLoader.java +++ b/scripting/workben/mod/_scripting/TestDataLoader.java @@ -44,10 +44,9 @@ public class TestDataLoader { if (!f.exists()) return; - BufferedReader in; try { - in = new BufferedReader(new FileReader(f)); + BufferedReader in = new BufferedReader(new FileReader(f)); String s, previous, current; ArrayList<Parameters> list = new ArrayList<Parameters>(11); @@ -59,6 +58,7 @@ public class TestDataLoader { list.add(getParameters(st)); } else { + in.close(); return; } @@ -77,6 +77,7 @@ public class TestDataLoader { } tEnv.addObjRelation(previous, list); + in.close(); } catch (IOException ioe) { } |