Author: sebb
Date: Thu Sep 25 16:29:18 2008
New Revision: 699130
URL: http://svn.apache.org/viewvc?rev=699130&view=rev
Log:
Ensure files are closed
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HeaderManager.java
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java?rev=699130&r1=699129&r2=699130&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/AuthManager.java
Thu Sep 25 16:29:18 2008
@@ -32,6 +32,7 @@
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
+import org.apache.commons.io.IOUtils;
import org.apache.jmeter.config.ConfigElement;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
@@ -240,38 +241,40 @@
if (!file.isAbsolute()) {
file = new File(System.getProperty("user.dir") + File.separator +
authFile);
}
- BufferedReader reader = null;
- if (file.canRead()) {
- reader = new BufferedReader(new FileReader(file));
- } else {
+ if (!file.canRead()) {
throw new IOException("The file you specified cannot be read.");
}
- String line;
+ BufferedReader reader = null;
boolean ok = true;
- while ((line = reader.readLine()) != null) {
- try {
- if (line.startsWith("#") || line.trim().length() == 0) {
//$NON-NLS-1$
- continue;
- }
- StringTokenizer st = new StringTokenizer(line, "\t");
//$NON-NLS-1$
- String url = st.nextToken();
- String user = st.nextToken();
- String pass = st.nextToken();
- String domain = "";
- String realm = "";
- if (st.hasMoreTokens()){// Allow for old format file without
the extra columnns
- domain = st.nextToken();
- realm = st.nextToken();
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ try {
+ if (line.startsWith("#") || line.trim().length() == 0) {
//$NON-NLS-1$
+ continue;
+ }
+ StringTokenizer st = new StringTokenizer(line, "\t");
//$NON-NLS-1$
+ String url = st.nextToken();
+ String user = st.nextToken();
+ String pass = st.nextToken();
+ String domain = "";
+ String realm = "";
+ if (st.hasMoreTokens()){// Allow for old format file
without the extra columnns
+ domain = st.nextToken();
+ realm = st.nextToken();
+ }
+ Authorization auth = new Authorization(url, user,
pass,domain,realm);
+ getAuthObjects().addItem(auth);
+ } catch (NoSuchElementException e) {
+ log.error("Error parsing auth line: '" + line + "'");
+ ok = false;
}
- Authorization auth = new Authorization(url, user,
pass,domain,realm);
- getAuthObjects().addItem(auth);
- } catch (NoSuchElementException e) {
- log.error("Error parsing auth line: '" + line + "'");
- ok = false;
}
+ } finally {
+ IOUtils.closeQuietly(reader);
}
- reader.close();
if (!ok){
JMeterUtils.reportErrorToUser("One or more errors found when
reading the Auth file - see the log file");
}
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HeaderManager.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HeaderManager.java?rev=699130&r1=699129&r2=699130&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HeaderManager.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/HeaderManager.java
Thu Sep 25 16:29:18 2008
@@ -29,6 +29,7 @@
import java.util.Enumeration;
import java.util.Vector;
+import org.apache.commons.io.IOUtils;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.jmeter.util.JMeterUtils;
@@ -114,29 +115,31 @@
file = new File(System.getProperty("user.dir")// $NON-NLS-1$
+ File.separator + headerFile);
}
- BufferedReader reader = null;
- if (file.canRead()) {
- reader = new BufferedReader(new FileReader(file));
- } else {
+ if (!file.canRead()) {
throw new IOException("The file you specified cannot be read.");
}
- String line;
- while ((line = reader.readLine()) != null) {
- try {
- if (line.startsWith("#") || line.trim().length() == 0) {//
$NON-NLS-1$
- continue;
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ try {
+ if (line.startsWith("#") || line.trim().length() == 0) {//
$NON-NLS-1$
+ continue;
+ }
+ String[] st = JOrphanUtils.split(line, "\t", " ");//
$NON-NLS-1$ $NON-NLS-2$
+ int name = 0;
+ int value = 1;
+ Header header = new Header(st[name], st[value]);
+ getHeaders().addItem(header);
+ } catch (Exception e) {
+ throw new IOException("Error parsing header line\n\t'" +
line + "'\n\t" + e);
}
- String[] st = JOrphanUtils.split(line, "\t", " ");//
$NON-NLS-1$ $NON-NLS-2$
- int name = 0;
- int value = 1;
- Header header = new Header(st[name], st[value]);
- getHeaders().addItem(header);
- } catch (Exception e) {
- throw new IOException("Error parsing header line\n\t'" + line
+ "'\n\t" + e);
}
+ } finally {
+ IOUtils.closeQuietly(reader);
}
- reader.close();
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]