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

[java] transforming a file to itself - buffered?

Subject: [java] transforming a file to itself - buffered?
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Tue, 04 Jun 2002 10:34:44 -0700
user mapped section
Hi,

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));

Is there any way to do buffered reads and writes to this file? Is there a benefit to doing this?

Is there a way to use the new 1.4 non blocking I/O (java.nio)?
<random_thought> The code below should(?) work on the entire file, but could you possibly identify a section (nodeset) of an XML file and perform a transformation on it? Is this just silly?</random_thought>


I tried to do the following but I get an error in saxon 6.52 saying: (The requested operation cannot be performed on a file with a user-mapped section open)
--------
RandomAccessFile in = new RandomAccessFile(_context.getRealPath(_xml), "rw");
FileChannel channel = in.getChannel();
Charset set = Charset.forName("US-ASCII");
CharsetDecoder decoder = set.newDecoder();
MappedByteBuffer bytes = channel.map(FileChannel.MapMode.READ_WRITE, 0, (int)channel.size());
CharBuffer chars = decoder.decode(bytes);


StreamSource source = new StreamSource(new CharArrayReader(chars.array()));
StreamSource result_source = new StreamSource(new CharArrayReader(chars.array()),
servlet_context.getRealPath(_xml));
StreamResult result = new StreamResult(result_source);


transformer.transform(source, result);
-----------

thanks for any help,
-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.