You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2017/02/18 11:09:14 UTC
svn commit: r1783509 -
/jmeter/trunk/src/core/org/apache/jmeter/util/BeanShellClient.java
Author: fschumacher
Date: Sat Feb 18 11:09:14 2017
New Revision: 1783509
URL: http://svn.apache.org/viewvc?rev=1783509&view=rev
Log:
Use try-with statement to close all streams.
Modified:
jmeter/trunk/src/core/org/apache/jmeter/util/BeanShellClient.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/util/BeanShellClient.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/BeanShellClient.java?rev=1783509&r1=1783508&r2=1783509&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/BeanShellClient.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/BeanShellClient.java Sat Feb 18 11:09:14 2017
@@ -51,33 +51,31 @@ public class BeanShellClient {
System.out.println("Connecting to BSH server on "+host+":"+portString);
- Socket sock = new Socket(host,port);
- InputStream is = sock.getInputStream();
- SockRead sockRead = new SockRead(is);
- sockRead.start();
-
- OutputStream os = sock.getOutputStream();
- sendLine("bsh.prompt=\"\";",os);// Prompt is unnecessary
-
- sendLine("String [] args={",os);
- for (int i=MINARGS; i<args.length;i++){
- sendLine("\""+args[i]+"\",\n",os);
+ try (Socket sock = new Socket(host,port);
+ InputStream is = sock.getInputStream();
+ OutputStream os = sock.getOutputStream()) {
+ SockRead sockRead = new SockRead(is);
+ sockRead.start();
+
+ sendLine("bsh.prompt=\"\";", os);// Prompt is unnecessary
+
+ sendLine("String [] args={", os);
+ for (int i = MINARGS; i < args.length; i++) {
+ sendLine("\"" + args[i] + "\",\n", os);
+ }
+ sendLine("};", os);
+
+ int b;
+ try (InputStreamReader fis = new FileReader(file)) {
+ while ((b = fis.read()) != -1) {
+ os.write(b);
+ }
+ }
+ sendLine("bsh.prompt=\"bsh % \";", os);// Reset for other users
+ os.flush();
+ sock.shutdownOutput(); // Tell server that we are done
+ sockRead.join(); // wait for script to finish
}
- sendLine("};",os);
-
- int b;
- InputStreamReader fis = new FileReader(file);
- while ((b=fis.read()) != -1){
- os.write(b);
- }
- fis.close();
- sendLine("bsh.prompt=\"bsh % \";",os);// Reset for other users
- os.flush();
- sock.shutdownOutput(); // Tell server that we are done
- sockRead.join(); // wait for script to finish
- is.close();
- os.close();
- sock.close();
}
private static void sendLine( String line, OutputStream outPipe )