Author: fschumacher
Date: Mon Feb 12 10:24:58 2018
New Revision: 1823937

URL: http://svn.apache.org/viewvc?rev=1823937&view=rev
Log:
Use try-with syntax, convert to stream usage and return early when no file was 
given.

Modified:
    
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java

Modified: 
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java?rev=1823937&r1=1823936&r2=1823937&view=diff
==============================================================================
--- 
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
 (original)
+++ 
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/parser/TestHTMLParser.java
 Mon Feb 12 10:24:58 2018
@@ -26,12 +26,14 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 import java.util.TreeSet;
 import java.util.Vector;
+import java.util.stream.Collectors;
 
 import org.apache.jmeter.junit.JMeterTestCaseJUnit;
 import org.apache.jmeter.util.JMeterUtils;
@@ -423,16 +425,12 @@ public class TestHTMLParser extends JMet
 
     // Get expected results as a List
     private static List<String> getFile(String file) throws Exception {
-        ArrayList<String> al = new ArrayList<>();
-        if (file != null && file.length() > 0) {
-            BufferedReader br = new BufferedReader(new 
FileReader(findTestFile(file)));
-            String line = br.readLine();
-            while (line != null) {
-                al.add(line);
-                line = br.readLine();
-            }
-            br.close();
+        if (file == null || file.isEmpty()) {
+            return Collections.emptyList();
+        }
+        try (FileReader fr = new FileReader(findTestFile(file));
+                BufferedReader br = new BufferedReader(fr)) {
+            return br.lines().collect(Collectors.toList());
         }
-        return al;
     }
 }


Reply via email to