Skip to content

Commit e7acd28

Browse files
committed
Simplify InputStream to String conversion using Java 11+ API
Replace manual BufferedReader-based InputStream to String conversion with Java 11+ InputStream.readAllBytes() as suggested by the TODO comment. This change: - Removes the TODO asking for Guava replacement - Uses standard Java 11+ API instead of external dependency - Reduces code complexity from 15 lines to 8 lines - Removes unused BufferedReader and InputStreamReader imports
1 parent e294ce8 commit e7acd28

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

fineract-provider/src/main/java/org/apache/fineract/template/service/TemplateMergeService.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
import com.github.mustachejava.DefaultMustacheFactory;
2323
import com.github.mustachejava.Mustache;
2424
import com.github.mustachejava.MustacheFactory;
25-
import java.io.BufferedReader;
2625
import java.io.IOException;
2726
import java.io.InputStream;
28-
import java.io.InputStreamReader;
2927
import java.io.StringReader;
3028
import java.io.StringWriter;
3129
import java.net.Authenticator;
@@ -55,21 +53,14 @@ public class TemplateMergeService {
5553

5654
private final FineractProperties fineractProperties;
5755

58-
// TODO Replace this with appropriate alternative available in Guava
56+
// Simplified using Java 11+ InputStream.readAllBytes() instead of manual buffering
5957
private static String getStringFromInputStream(final InputStream is) {
60-
final StringBuilder sb = new StringBuilder();
61-
62-
String line;
63-
try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
64-
65-
while ((line = br.readLine()) != null) {
66-
sb.append(line);
67-
}
58+
try {
59+
return new String(is.readAllBytes(), StandardCharsets.UTF_8);
6860
} catch (final IOException e) {
6961
log.error("getStringFromInputStream() failed", e);
62+
return "";
7063
}
71-
72-
return sb.toString();
7364
}
7465

7566
public String compile(final Template template, final Map<String, Object> scopes) {

0 commit comments

Comments
 (0)