[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [java] transforming a file to itself - buffered?

Subject: Re: [java] transforming a file to itself - buffered?
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Tue, 04 Jun 2002 14:34:05 -0700
java write file buffered
Hi and thanks Joerg,

J.Pietschmann wrote:

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.

The reason I want to use java.nio is because there is a locking method. It can lock the entire file or parts of the file. I am just experimenting... I can open the file and provide the source through nio. I would like to be able to write to the part of the document that i have specified. Currently I only let one user access a particular file at a time.



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...

Why? Am I doing something stupid? I have only had a few concurrent users at any one time and there has not been any problems. The user base for any 'one' set of files is pretty small (1-10 users).


thanks again,
-Rob



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.