[jbosstools-commits] JBoss Tools SVN: r43636 - in trunk/common/plugins: org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/reporting and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Sep 13 03:56:38 EDT 2012


Author: fbricon
Date: 2012-09-13 03:56:37 -0400 (Thu, 13 Sep 2012)
New Revision: 43636

Modified:
   trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/zip/UnzipOperation.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/reporting/ReportProblemWizard.java
Log:
Fix resource leaks

Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/zip/UnzipOperation.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/zip/UnzipOperation.java	2012-09-13 07:52:48 UTC (rev 43635)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/zip/UnzipOperation.java	2012-09-13 07:56:37 UTC (rev 43636)
@@ -90,14 +90,25 @@
 			File outputFile = new File(destination,file.getName());
 			outputFile.getParentFile().mkdirs();
 			outputFile.createNewFile();
-			BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile),BUFFER_SIZE);
-			BufferedInputStream in = new BufferedInputStream(zipFile.getInputStream(file));
-			byte[] buff = new byte[BUFFER_SIZE];
-			int n = -1;
-			while((n = in.read(buff,0,buff.length))>-1) {
-				out.write(buff, 0, n);
+			BufferedOutputStream out = null;
+			BufferedInputStream in =null; 
+			try {
+				out = new BufferedOutputStream(new FileOutputStream(outputFile),BUFFER_SIZE);
+				in= new BufferedInputStream(zipFile.getInputStream(file));
+				byte[] buff = new byte[BUFFER_SIZE];
+				int n = -1;
+				while((n = in.read(buff,0,buff.length))>-1) {
+					out.write(buff, 0, n);
+				}
+				out.flush();
+			} finally {
+				if (in != null) {
+					in.close();
+				}
+				if (out != null) {
+					out.close();
+				}
 			}
-			out.flush();
 		}
 	}
 }

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/reporting/ReportProblemWizard.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/reporting/ReportProblemWizard.java	2012-09-13 07:52:48 UTC (rev 43635)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/reporting/ReportProblemWizard.java	2012-09-13 07:56:37 UTC (rev 43636)
@@ -38,7 +38,6 @@
 import org.eclipse.jface.dialogs.DialogPage;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
@@ -62,7 +61,6 @@
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Layout;
-import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.about.ISystemSummarySection;
@@ -85,7 +83,6 @@
 import org.jboss.tools.common.model.ui.widgets.TextAndReferenceComponent;
 import org.jboss.tools.common.model.ui.wizards.query.AbstractQueryWizard;
 import org.jboss.tools.common.model.ui.wizards.query.AbstractQueryWizardView;
-import org.jboss.tools.common.model.ui.wizards.query.IQueryDialog;
 import org.jboss.tools.common.reporting.ProblemReportingHelper;
 
 public class ReportProblemWizard extends AbstractQueryWizard {
@@ -251,13 +248,14 @@
 	 * @return
 	 */
 	private byte[] getEclipseLogContent() {
-		StringBuffer sb = new StringBuffer();
+		StringBuilder sb = new StringBuilder();
 		String location = Platform.getLogFileLocation().toOSString();
 		File f = new File(location);
 		if(!f.isFile()) return sb.toString().getBytes();
 
+		InputStreamReader in = null;
 		try {
-			InputStreamReader in = new FileReader(location);
+			in = new FileReader(location);
 
 			char[] tempBuffer = new char[512];
 			int len = 0;
@@ -268,6 +266,15 @@
 		} catch (IOException e) {
 			ModelUIPlugin.getPluginLog().logError(e);
 		}
+		finally {
+			if (in != null)	{
+				try {
+					in.close();
+				} catch (Exception ignore) {
+					//Ignore
+				}
+			}
+		}
 
 		return getLogByCurentDate(sb.toString()).getBytes();
 	};



More information about the jbosstools-commits mailing list