def render(context, logString, template): sWriter = StringWriter() fIS = None try: sWriter.append(MSGTEMPLATE_PREFIX) fIS = FileInputStream(File(MSGTEMPLATE_DIR, template)) Velocity.evaluate(context, sWriter, logString, fIS) sWriter.append(MSGTEMPLATE_SUFFIX) return sWriter.toString() finally: if fIS: fIS.close()