Ensure file input stream are closed in both normal and error cases.

pull/93/head
luccioman 8 years ago
parent a0dfbaca6a
commit 0806de8fdc

@ -303,10 +303,20 @@ public class DictionaryLoader_p {
}
if (post.containsKey("syn0Activate")) {
FileInputStream inStream = null;
try {
FileUtils.copy(new FileInputStream(synonym_de_default), synonym_de_production);
inStream = new FileInputStream(synonym_de_default);
FileUtils.copy(inStream, synonym_de_production);
} catch (IOException e) {
ConcurrentLog.logException(e);
} finally {
if(inStream != null) {
try {
inStream.close();
} catch (IOException ignored) {
ConcurrentLog.warn("DictionaryLoader", "Could not close file " + synonym_de_default.getName());
}
}
}
SynonymLibrary.init(synonyms_path);
}

@ -1105,11 +1105,25 @@ public class YaCyDefaultServlet extends HttpServlet {
response.setContentType(mimeType);
response.setStatus(HttpServletResponse.SC_OK);
ByteArrayOutputStream bas = new ByteArrayOutputStream(4096);
// apply templates
TemplateEngine.writeTemplate(targetFile.getName(), fis, bas, templatePatterns);
fis.close();
// handle SSI
parseSSI (bas.toByteArray(),request,response);
try {
// apply templates
TemplateEngine.writeTemplate(targetFile.getName(), fis, bas, templatePatterns);
// handle SSI
parseSSI (bas.toByteArray(),request,response);
} finally {
try {
fis.close();
} catch(IOException ignored) {
ConcurrentLog.warn("FILEHANDLER", "YaCyDefaultServlet: could not close target file " + targetFile.getName());
}
try {
bas.close();
} catch(IOException ignored) {
/* Should never happen with a ByteArrayOutputStream */
}
}
}
}
}

Loading…
Cancel
Save