fileDownloadActionListener download PDF file in ADF 11
Hi ,
I have a requirement to download the PDF file on the file system. I am using fileDownloadActionListener . I am using the following code .
<af:commandLink text="Download the stored PDF">
<af:fileDownloadActionListener filename="#{row.FirstName}.pdf"
contentType="application/pdf;charset=UTF-8"
method="#{FindReports.reportPDFDownload}"/>
</af:commandLink>
Managed bean code
public void reportPDFDownload(FacesContext facesContext,
OutputStream outputStream) throws IOException {
OutputStreamWriter w = new OutputStreamWriter(outputStream, "UTF-8");
InputStream in = getReportDocument(); // fetch the data from DB
System.out.println("input file is :" + in);
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int length;
while ((length = in.read(buffer)) > 0) {
w.write(buffer.toString());
}
w.flush();
w.close();
}
When I open the downloaded file , it says file corrupted or not correctly decoded. I checked the downloaded file size, it's 10 bytes.
Could any one suggest me how to resolve the issue ?
Thanks,
Reena