I've writing this code to serve a file export. I did not used await()
and family, but a piped stream and a Job.
I just try on my localhost and with single request, and it works ...
I'm happy ;-) But I'm afraid to follow a bad way ...
Could you please tell me if it's the right way ? Do you know a better
way to serve a file ?
public static void downloadExcel() {
try {
final PipedOutputStream pos = new PipedOutputStream();
final PipedInputStream pis = new PipedInputStream(pos);
new ExcelExportJob(pos).now();
response.contentType = "application/excel";
// doesn't work: java.io.IOException: Already connected
// response.direct = new PipedInputStream(pos);
renderBinary(pis, "toto.xls");
} catch (Exception ex) {
Logger.getLogger(Participants.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static class ExcelExportJob extends Job {
private final BufferedOutputStream outputStream;
public ExcelExportJob(OutputStream outputStream) {
this.outputStream = new BufferedOutputStream(outputStream);
}
@Override
public void doJob() throws Exception {
FileExport.writeFile( this.outputStream, FileFormat.Excel );
this.outputStream.flush();
this.outputStream.close();
}
}
Thanks
Cyrille.
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>
--
Guillaume Bort, http://guillaume.bort.fr