Skip to content

Commit e179580

Browse files
committed
new way for getting file content from filesystem
1 parent 11419cd commit e179580

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/test/java/org/owasp/esapi/reference/ExtensiveEncoderURITest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import static org.junit.Assert.assertEquals;
44

5-
import java.io.File;
5+
import java.io.BufferedReader;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.io.InputStreamReader;
69
import java.net.URL;
710
import java.nio.charset.StandardCharsets;
8-
import java.nio.file.Files;
911
import java.util.ArrayList;
1012
import java.util.Collection;
1113
import java.util.List;
@@ -34,14 +36,24 @@ public ExtensiveEncoderURITest(String uri){
3436
@Parameters
3537
public static Collection<String> getMyUris() throws Exception{
3638
URL url = ExtensiveEncoderURITest.class.getResource("/urisForTest.txt");
37-
String fileName = url.getFile();
38-
File urisForText = new File(fileName);
39-
40-
inputs = Files.readAllLines(urisForText.toPath(), StandardCharsets.UTF_8);
4139

40+
try( InputStream is = url.openStream() ) {
41+
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
42+
BufferedReader br = new BufferedReader(isr);
43+
inputs = readAllLines(br);
44+
}
4245
return inputs;
4346
}
44-
47+
48+
private static List<String> readAllLines(BufferedReader br) throws IOException {
49+
List<String> lines = new ArrayList<>();
50+
String line;
51+
while ((line = br.readLine()) != null) {
52+
lines.add(line);
53+
}
54+
return lines;
55+
}
56+
4557
@Test
4658
public void testUrlsFromFile() throws Exception{
4759
assertEquals(this.expected, v.isValidURI("URL", uri, false));

0 commit comments

Comments
 (0)