projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use try-with-resources
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
web
/
ReloadingPage.java
diff --git
a/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java
b/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java
index
f89bbed
..
bc18816
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ReloadingPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ReloadingPage.java
@@
-24,7
+24,6
@@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.OutputStream;
-import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.io.StreamCopier;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Request;
import net.pterodactylus.util.io.StreamCopier;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Request;
@@
-73,19
+72,12
@@
public class ReloadingPage<REQ extends Request> implements Page<REQ> {
String path = request.getUri().getPath();
int lastSlash = path.lastIndexOf('/');
String filename = path.substring(lastSlash + 1);
String path = request.getUri().getPath();
int lastSlash = path.lastIndexOf('/');
String filename = path.substring(lastSlash + 1);
-
InputStream fileInputStream
;
-
try
{
-
fileInputStream = new FileInputStream(new File(filesystemPath, filename)
);
+
try (InputStream fileInputStream = new FileInputStream(new File(filesystemPath, filename))
;
+
OutputStream contentOutputStream = response.getContent())
{
+
StreamCopier.copy(fileInputStream, contentOutputStream
);
} catch (FileNotFoundException fnfe1) {
return response.setStatusCode(404).setStatusText("Not found.");
}
} catch (FileNotFoundException fnfe1) {
return response.setStatusCode(404).setStatusText("Not found.");
}
- OutputStream contentOutputStream = response.getContent();
- try {
- StreamCopier.copy(fileInputStream, contentOutputStream);
- } finally {
- Closer.close(fileInputStream);
- Closer.close(contentOutputStream);
- }
return response.setStatusCode(200).setStatusText("OK").setContentType(mimeType);
}
}
return response.setStatusCode(200).setStatusText("OK").setContentType(mimeType);
}
}