Hi Frank, you really shouldn’t deliver your PDF file that way because by this you will load the file completely into memory. Currently your PDF file is only 10MB but can you be sure that it will have that size all the time? What if your PDF file will be 100MB and 10 users concurrently click your download button? Your application will suddenly take 1GB of RAM only for sending the files which could get your application crashing.
You can give WOResponse an input stream so it will be streamed directly to the
client taking only a fraction of the memory footprint and be faster:
public WOActionResults fichePrint() {
File file = new File("/tmp/test.pdf“);
long fileSize = file.length();
WOResponse response = new WOResponse();
response.setHeader("application/pdf", "Content-Type");
response.setHeader(Long.toString(fileSize), "content-length");
response.setHeader("inline; filename=test.pdf", "Content-Disposition");
response.setContentStream(new FileInputStream(file), 32768, fileSize);
return response;
}
Even better you achieve the same result with less code and are safer regarding
errors like not closing streams in certain situations.
jw
Am 01.11.2014 um 16:26 schrieb Frank Stock <[email protected]>:
> Hi All,
>
> I have moved my application from MacOS server 10.6 to 10.9.5.
> I have done a complete new installation. The application works fine but when
> I create a pdf it takes about 25 seconds to see it in the browser.
> The pdf is about 10MB. When I do a direct connect I can see the pdf without
> delay.
>
> I have created a new Wonder Application with only the following code:
>
> public WOActionResults fichePrint() {
> String filename = "/tmp/test.pdf"; // test.pdf is a 10MB file
> ByteArrayOutputStream outputStream=null;
> try {
> outputStream = new ByteArrayOutputStream();
> InputStream inputStream = new
> FileInputStream(filename);
>
>
> int data;
> while( (data = inputStream.read()) >= 0 ) {
> outputStream.write(data);
> }
> inputStream.close();
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> // It takes 8 seconds to load the file
> System.out.println("Read");
>
> WOResponse response=new WOResponse();
> response.setHeader("application/pdf", "Content-Type");
> response.setHeader(Integer.toString(outputStream.size()),
> "content-length");
> response.setHeader("inline; filename=test.pdf",
> "Content-Disposition");
> response.setContent(new NSData(outputStream.toByteArray()));
>
>
>
>
>
>
> return response;
> }
>
> Has this something to do with Apache? Where can I find more information to
> solve this?
>
> Thanks in advance,
> Frank Stock
> Belgium
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
