Re: out.flush()

2007-03-13 Thread Jeff Vannest
 Could you please state which OutputStream implementation are
 used in your code?

SorryI didn't answer your question: java.io.FileOutputStream and
java.io.BufferedOutputStream.

A code snippet from the servlet appears below.

Thanks,
Jeff




// Setup output
OutputStream out = new java.io.FileOutputStream(pdfFile);
out = new java.io.BufferedOutputStream(out);

// Transform the XML+XSLT to PDF
try {

   // Create and configure the FOUserAgent
   FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
   foUserAgent.setProducer(Oracle Pluggable Destination - DesXslFo);
   foUserAgent.setCreator(X);
   foUserAgent.setAuthor(X);
   foUserAgent.setCreationDate(new Date());
   foUserAgent.setBaseURL(file:/// + transformDir);

   // Construct fop with desired output format
   Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);

   // Setup the transformer with the XSLT
   TransformerFactory factory = TransformerFactory.newInstance();
   Transformer transformer = factory.newTransformer(new
StreamSource(xsltFile));

   // Set the XSLT stylesheet version being used
   transformer.setParameter(versionParam, xsltVersion);

   // Setup input for XSLT transformation
   Source src = new StreamSource(xmlFile);

   // Resulting SAX events (the generated FO) must be piped through to FOP
   Result res = new SAXResult(fop.getDefaultHandler());

   // Start XSLT transformation and FOP processing
   transformer.transform(src, res);

   // Flush the buffered output before exiting
   out.flush();
   out.close();

   // Help garbage collection
   res = null;
   src = null;
   transformer = null;
   factory = null;
   fop = null;
   foUserAgent = null;

} catch (Exception e) {
   try { out.close(); } catch (Exception ignore) {}
   throw new Exception(e.getClass() + :  + e.getMessage());
}   transformer = null;
factory = null;
fop = null;
foUserAgent = null;

} catch (Exception e) {
try { out.close(); } catch (Exception ignore) {}
throw new Exception(e.getClass() + :  + e.getMessage());
}



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: out.flush()

2007-03-13 Thread Jeremias Maerki
Interesting. I think I shall try to reproduce the problem in a quiet
moment.

Thanks for the code snippet. A note on that: I consider it better style
to put the close() in a finally section so you don't have to make sure
that the close() is called in every situation (exception or not).

On 13.03.2007 01:28:17 Jeff Vannest wrote:
 Closing the buffered out without flushing causes the PDF file to be closed
 before all data is written to it. Originally when I started working with the
 embedded FOP I had this problem...adding the flush got rid of the problem
 completely.
 
 Another user had the same problem and reported it on 3/6/07 in a message
 titled, FOP 0.93 generated a damaged PDF File. Liam responded on 3/7/07 to
 do a flush before the close.
 
 According to
 http://java.sun.com/j2se/1.4.2/docs/api/java/io/FilterOutputStream.html#clos
 e(), the flush() should be implicit, which agrees with your response.
 
 On a possibly related note, I only experienced the problem within the
 context of my servlet, never on my local system, so I'm not ruling out a
 java bug.
 
 Jeff



Jeremias Maerki


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



out.flush()

2007-03-12 Thread Jeff Vannest
Will someone add out.flush() to the embedding example on the FOP
website...for example, at
http://xmlgraphics.apache.org/fop/0.93/embedding.html?

It seems a shame that everyone embedding FOP learns to flush() by trial and
error.

Thanks!
Jeff




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: out.flush()

2007-03-12 Thread Jeremias Maerki
That's the first time I head someone mention that. Why do you think this
is necessary? The example uses a try..finally calling out.close() in the
finally section. This normally causes an implicit flush() (at least for
all implementations of OutputStream I know and which do actually
implement flush()). So I see no need for an explicit flush(). Could you
please state which OutputStream implementation are used in your code?

On 12.03.2007 22:52:30 Jeff Vannest wrote:
 Will someone add out.flush() to the embedding example on the FOP
 website...for example, at
 http://xmlgraphics.apache.org/fop/0.93/embedding.html?
 
 It seems a shame that everyone embedding FOP learns to flush() by trial and
 error.
 
 Thanks!
 Jeff


Jeremias Maerki


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: out.flush()

2007-03-12 Thread Jeff Vannest
Closing the buffered out without flushing causes the PDF file to be closed
before all data is written to it. Originally when I started working with the
embedded FOP I had this problem...adding the flush got rid of the problem
completely.

Another user had the same problem and reported it on 3/6/07 in a message
titled, FOP 0.93 generated a damaged PDF File. Liam responded on 3/7/07 to
do a flush before the close.

According to
http://java.sun.com/j2se/1.4.2/docs/api/java/io/FilterOutputStream.html#clos
e(), the flush() should be implicit, which agrees with your response.

On a possibly related note, I only experienced the problem within the
context of my servlet, never on my local system, so I'm not ruling out a
java bug.

Jeff




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]