Closed
Description
The InputStream was closed twice, causing some following errors.
io/avaje/jex/staticcontent/StaticClassResourceHandler.java
private void sendFile(Context ctx, HttpExchange jdkExchange, String urlPath, File canonicalFile)
throws IOException {
try (var fis = new FileInputStream(canonicalFile)) { // The second closing of InputStream (fis)
String mimeType = lookupMime(urlPath);
ctx.header(CONTENT_TYPE, mimeType);
ctx.headers(headers);
if (precompress) {
addCachedEntry(ctx, urlPath, fis);
return;
}
ctx.write(fis); // Inside the first closing of InputStream (fis)
} catch (FileNotFoundException e) {
throw404(jdkExchange);
}
}
io/avaje/jex/staticcontent/StaticFileHandler.java
private void sendFile(Context ctx, HttpExchange jdkExchange, String urlPath, File canonicalFile)
throws IOException {
try (var fis = new FileInputStream(canonicalFile)) { // The second closing of InputStream (fis)
String mimeType = lookupMime(urlPath);
ctx.header(CONTENT_TYPE, mimeType);
ctx.headers(headers);
if (precompress) {
addCachedEntry(ctx, urlPath, fis);
return;
}
ctx.write(fis); // Inside the first closing of InputStream (fis)
} catch (FileNotFoundException e) {
throw404(jdkExchange);
}
}
io/avaje/jex/core/JdkContext.java
@Override
public void write(InputStream is) {
try (is; var os = outputStream()) { // The first closing of InputStream (is)
is.transferTo(os);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}