Skip to content

Commit

Permalink
fix: StaticFileHandler의 인풋 스트림 close 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
zillionme committed Sep 4, 2023
1 parent fae9599 commit 144b475
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;

import static org.apache.coyote.http11.common.HttpStatus.OK;
Expand Down Expand Up @@ -47,13 +48,14 @@ public static HttpResponse handle(final String requestURI, RequestHeader request
}

private static String findResponseBody(final String requestURI) throws IOException {
String requestedFile = ClassLoader.getSystemClassLoader().getResource("static" + requestURI).getFile();
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader(requestedFile, Charset.forName("UTF-8")));
String str;
while ((str = br.readLine()) != null) {
sb.append(str + "\n");
URL requestedFile = ClassLoader.getSystemClassLoader().getResource("static" + requestURI);
try (BufferedReader br = new BufferedReader(new FileReader(requestedFile.getFile(), Charset.forName("UTF-8")))) {
StringBuilder sb = new StringBuilder();
String str;
while ((str = br.readLine()) != null) {
sb.append(str + "\n");
}
return sb.toString();
}
return sb.toString();
}
}

0 comments on commit 144b475

Please sign in to comment.