Allow Faces.sendFile() to take some sort of OutputStreamCallback #194

kalgon opened this Issue Jan 6, 2016 · 4 comments


None yet

2 participants

kalgon commented Jan 6, 2016

It would be nice if there was a Faces.sendFile() method which would take some sort of OutputStreamCallback (or a Callback.WithArgument<OutputStream>) like this:

interface OutputStreamCallback {
    void writeInto(OutputStream outputStream) throws (IO)Exception;

I am asking for this because some processes are naturally easier to use with OutputStream rather than InputStream (like marshalling a JAXB object).

Faces.sendFile(os -> marshaller.marshal(myobject, os), "myfile.xml", true);
BalusC commented Jan 26, 2016

idea is nice, but exception handling in lambda is irksome. I'm wary of declaring "throws Exception" in the API.

kalgon commented Jan 28, 2016

I used a lambda here for brevity but I don't mind using an anonymous class that only throws IOException if that is OK for you.

As this method would not be in charge of writing on the output stream anymore, the (optional) content-length will have to be calculated by wrapping the response output stream in some sort of CountingByteOutputStream.

I came across the need for such a method one more time as I was generating PDFs with FOP.

BalusC commented Jan 28, 2016

Single-method interfaces like OmniFaces Callback can just directly be used as lambdas in Java8, even without @FunctionalInterface annotation.

I'll add one for output. I'll skip content length as that would require an uncommitted response (and thus the entire output in server's memory). User can always opt for temp file approach instead and then passing via existing methods.

BalusC commented Jan 28, 2016

It's available in today's 2.3 snapshot.

@BalusC BalusC closed this Jan 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment