Skip to content

Commit

Permalink
fix regression with FileStream
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 28, 2023
1 parent 18a7bf9 commit 4378236
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ public static String call(PageContext pc, Object file, Object data) throws PageE

public static String call(PageContext pc, Object file, Object data, String charset) throws PageException {
FileStreamWrapper fsw = null;
boolean close = false;
if (StringUtil.isEmpty(charset, true)) charset = ((PageContextImpl) pc).getResourceCharset().name();
Resource res = null;
try {
if (file instanceof FileStreamWrapper) {
fsw = (FileStreamWrapper) file;
}
else {
close = true;
res = Caster.toResource(pc, file, false);
pc.getConfig().getSecurityManager().checkFileLocation(res);
fsw = new FileStreamWrapperWrite(res, charset, true, false);
Expand All @@ -54,7 +56,7 @@ public static String call(PageContext pc, Object file, Object data, String chars
throw Caster.toPageException(e);
}
finally {
IOUtil.closeEL(fsw);
if (close) IOUtil.closeEL(fsw);
if (res != null) PageSourcePool.flush(pc, res);
else PageSourcePool.flush(pc, file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static String call(PageContext pc, Object obj, Object data, String charse
throw Caster.toPageException(e);
}
finally {
IOUtil.closeEL(fsw);
if (close) IOUtil.closeEL(fsw);
if (fsw != null) PageSourcePool.flush(pc, fsw);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;

import lucee.commons.io.IOUtil;
import lucee.commons.io.SystemUtil;
import lucee.commons.io.res.Resource;
import lucee.runtime.PageContext;
Expand All @@ -46,7 +47,7 @@ public static String call(PageContext pc, Object obj, String text) throws PageEx
fsw.write(text + SystemUtil.lineSeparator());
}
finally {
if (close && fsw != null) fsw.close();
if (close) IOUtil.closeEL(fsw);
}

}
Expand Down

0 comments on commit 4378236

Please sign in to comment.