This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: [java] transforming a file to itself - buffered?
- From: "J.Pietschmann" <j3322ptm at yahoo dot de>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 04 Jun 2002 22:59:01 +0200
- Subject: Re: [xsl] [java] transforming a file to itself - buffered?
- References: <007a01c207f4$9bb59ae0$6401a8c0@pcukmka> <3CF7B759.4196CDDD@mitre.org> <3CFCFA34.1030508@koberg.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Robert Koberg wrote:
What is the best way to handle transforming a file to itself?
Currently I do:
File source = new File(servlet_context.getRealPath(_xml));
transformer.transform(new StreamSource(source), new StreamResult(source));
Opening a file both for reading and writing at the same
time is always risky. Either write to a buffer, and write
the buffer to disk after the transformation has finished,
or write to a temporary file and rename to the original
file afterwards.
Something like;
ByteArrayOutputStream baos=new B...;
File source = new File(servlet_context.getRealPath(_xml));
transformer.transform(new StreamSource(source), new StreamResult(baos));
byte buf[]=baos.toByteArray();
new FileOutputStream(source).write(buf);
BTW doing this in a servlet context appears to be
rather strange...
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list