Skip to content

Commit 758860c

Browse files
committed
Normalize line endings in resource stream content to LF
Replace the buffer-copy approach with BufferedReader.readLine(), which strips CR/LF and reassembles lines with LF only - the same pattern all other resource loaders in the codebase already use. This also removes the now-unused copy() utility method.
1 parent f16ac81 commit 758860c

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

flexmark-ext-admonition/src/main/java/com/vladsch/flexmark/ext/admonition/AdmonitionExtension.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ public static Map<String, String> getQualifierSvgValueMap() {
148148

149149
public static String getInputStreamContent(InputStream inputStream) {
150150
try {
151-
InputStreamReader streamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
152-
StringWriter stringWriter = new StringWriter();
153-
copy(streamReader, stringWriter);
154-
stringWriter.close();
155-
return stringWriter.toString();
151+
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
152+
StringBuilder sb = new StringBuilder();
153+
String line;
154+
while ((line = reader.readLine()) != null) {
155+
sb.append(line).append('\n');
156+
}
157+
return sb.toString();
156158
} catch (Exception e) {
157159
e.printStackTrace();
158160
return "";
@@ -167,16 +169,6 @@ public static String getDefaultScript() {
167169
return getInputStreamContent(AdmonitionExtension.class.getResourceAsStream("/admonition.js"));
168170
}
169171

170-
public static void copy(Reader reader, Writer writer) throws IOException {
171-
char[] buffer = new char[4096];
172-
int n;
173-
while (-1 != (n = reader.read(buffer))) {
174-
writer.write(buffer, 0, n);
175-
}
176-
writer.flush();
177-
reader.close();
178-
}
179-
180172
private AdmonitionExtension() {
181173
}
182174

0 commit comments

Comments
 (0)