Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] [java] transforming a file to itself - buffered?

From: Robert Koberg <rob@---------->
To:
Date: 6/4/2002 9:44:00 AM
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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent