X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FFilesystemTemplate.java;h=7c7da4cf5d2f7c28a6fe374847fd25642458640f;hb=3335cbf7681220fcf95cff4895e025251211bf8e;hp=473c1916f3889dd28d52e589807ccba342506d88;hpb=e80ee9c75042771d91bdd7095ca225adc6c11e6c;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/FilesystemTemplate.java b/src/main/java/net/pterodactylus/sone/template/FilesystemTemplate.java
index 473c191..7c7da4c 100644
--- a/src/main/java/net/pterodactylus/sone/template/FilesystemTemplate.java
+++ b/src/main/java/net/pterodactylus/sone/template/FilesystemTemplate.java
@@ -2,7 +2,7 @@ package net.pterodactylus.sone.template;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -18,21 +18,17 @@ import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateException;
import net.pterodactylus.util.template.TemplateParser;
-import freenet.support.io.Closer;
-
import com.google.common.base.Charsets;
/**
* {@link Template} implementation that can be reloaded from the filesystem.
- *
- * @author David âBombeâ Roden
*/
public class FilesystemTemplate extends Template {
private final String filename;
- private final AtomicReference lastTemplate = new AtomicReference();
+ private final AtomicReference lastTemplate = new AtomicReference<>();
private final TemplateContext initialContext = new TemplateContext();
- private final List parts = new ArrayList();
+ private final List parts = new ArrayList<>();
public FilesystemTemplate(String filename) {
this.filename = filename;
@@ -46,28 +42,19 @@ public class FilesystemTemplate extends Template {
private void loadTemplate() {
File templateFile = new File(filename);
- if (!templateFile.exists()) {
- throw new TemplateFileNotFoundException(filename);
- }
if (templateWasLoaded() && !templateFileHasBeenModifiedAfterLoading(templateFile)) {
return;
}
- InputStream templateInputStream = null;
- Reader templateReader = null;
- try {
- templateInputStream = new FileInputStream(templateFile);
- templateReader = new InputStreamReader(templateInputStream, Charsets.UTF_8);
+ try (InputStream templateInputStream = new FileInputStream(templateFile);
+ Reader templateReader = new InputStreamReader(templateInputStream, Charsets.UTF_8)) {
Template template = TemplateParser.parse(templateReader);
lastTemplate.set(new LastLoadedTemplate(template));
template.getInitialContext().mergeContext(initialContext);
for (Part part : parts) {
template.add(part);
}
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
throw new TemplateFileNotFoundException(filename);
- } finally {
- Closer.close(templateReader);
- Closer.close(templateInputStream);
}
}
@@ -131,8 +118,6 @@ public class FilesystemTemplate extends Template {
/**
* Exception that signals that a template file could not be found.
- *
- * @author David âBombeâ Roden
*/
public static class TemplateFileNotFoundException extends RuntimeException {