BAEL-7131 - Updated for final review comments
This commit is contained in:
parent
03b2f8bb58
commit
63741db3d9
@ -2,7 +2,6 @@ package com.baeldung.inputstreamreader;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@ -23,11 +22,13 @@ public class InputStreamReaderUnitTest {
|
|||||||
List<String> lines = Arrays.asList(sampleTxt);
|
List<String> lines = Arrays.asList(sampleTxt);
|
||||||
Files.write(sampleOut, lines);
|
Files.write(sampleOut, lines);
|
||||||
String absolutePath = String.valueOf(sampleOut.toAbsolutePath());
|
String absolutePath = String.valueOf(sampleOut.toAbsolutePath());
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8))) {
|
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8)) {
|
||||||
String ln;
|
|
||||||
boolean isMatched = false;
|
boolean isMatched = false;
|
||||||
while ((ln = br.readLine()) != null) {
|
int b;
|
||||||
if (ln.contains(sampleTxt)) {
|
StringBuilder sb = new StringBuilder();
|
||||||
|
while ((b = reader.read()) != -1) {
|
||||||
|
sb.append((char) b);
|
||||||
|
if (sb.toString().contains(sampleTxt)) {
|
||||||
isMatched = true;
|
isMatched = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user