New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kalgon opened this Issue Jan 6, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@kalgon

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

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jan 26, 2016

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@kalgon

kalgon 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.

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

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jan 28, 2016

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jan 28, 2016

Member

It's available in today's 2.3 snapshot.

Member

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