This code is to get the pdf request from Flex application and generate pdf file which will be displayed in the flex application.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("I am in pdf Exporter get method");
int maxLength = req.getContentLength();
String method = req.getParameter("method");
String name = req.getParameter("name");
ServletInputStream si = req.getInputStream();
ServletOutputStream stream = resp.getOutputStream();
resp.setContentType("application/pdf");
resp.setContentLength(maxLength);
resp.setHeader("Content-Disposition", method + ";filename=" + name);
copyStreams(si, stream, 100);
stream.close();
}
//read the input stream and copy in to output steam
//Input stream will have pdf content which is coming from flex application
private void copyStreams(InputStream inStream, OutputStream outStream, int flushCount) throws IOException
{
int currentByte;
int flushCounter = 0;
while((currentByte = inStream.read()) != -1)
{
outStream.write(currentByte);
if(flushCounter++ > flushCount)
{
outStream.flush();
flushCounter = 0;
}
}
outStream.flush();
}