BAEL-7131 - Updated for final review comments

This commit is contained in:
adalagandev 2024-03-10 22:34:19 +01:00
parent 03b2f8bb58
commit 63741db3d9
1 changed files with 6 additions and 5 deletions

View File

@ -2,7 +2,6 @@ package com.baeldung.inputstreamreader;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
@ -23,11 +22,13 @@ public class InputStreamReaderUnitTest {
List<String> lines = Arrays.asList(sampleTxt);
Files.write(sampleOut, lines);
String absolutePath = String.valueOf(sampleOut.toAbsolutePath());
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8))) {
String ln;
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(absolutePath), StandardCharsets.UTF_8)) {
boolean isMatched = false;
while ((ln = br.readLine()) != null) {
if (ln.contains(sampleTxt)) {
int b;
StringBuilder sb = new StringBuilder();
while ((b = reader.read()) != -1) {
sb.append((char) b);
if (sb.toString().contains(sampleTxt)) {
isMatched = true;
break;
}