Skip to content

Commit

Permalink
Normalize line endings depending on the platform after reading the re…
Browse files Browse the repository at this point in the history
…source content
  • Loading branch information
besidev committed Sep 30, 2024
1 parent fe8eed9 commit a9aca70
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -143,7 +144,13 @@ public HttpServerImpl(@Nullable final Stage stage, @NotNull final HttpOptions op
private byte[] getResourceAsBytes(@NotNull final String name) throws IOException {
try (InputStream is = HttpServer.class.getResourceAsStream(name)) {
if (is != null) {
return is.readAllBytes();
// Read all bytes from the input stream
byte[] bytes = is.readAllBytes();
// Convert bytes to a string, normalize line endings, and convert back to bytes
String content = new String(bytes, StandardCharsets.UTF_8);
String normalizedContent = content.replace("\r\n", "\n")
.replace("\r", "\n");
return normalizedContent.getBytes(StandardCharsets.UTF_8);
}
}
return SPACE;
Expand Down

0 comments on commit a9aca70

Please sign in to comment.