Mon, 27 Aug 2007 05:20:32 -0700 (PDT), /richa/:
Fri, 24 Aug 2007 08:17:12 -0400, /Michael Glavassevich/:
Thu, 23 Aug 2007 22:46:25 -0700 (PDT), /richa/:
Does LSSerializer creates a thread of its own, while writing a file. I'm
using LSSerailizer.write() funtion to generate an xml file. and my function
is finishing before my whole file is written. There is no problem in file
generation. File is getting generated, but my function where i;m calling the
write function is finishing before.
Any idea why is this happening??
Fairly sure that the LSSerializer doesn't create it's own thread. Perhaps
this is happening because the actual file write is asynchronous.
Is there is any way i can make it synchronous?
This appears out of the Xerces scope, but with Java 1.4 you may try
invoking force(true) of the FileChannel obtained from
FileOutputStream or RandomAccessFile. This suggests you pass an
LSOutput initialized with a byteStream to the
LSSerializer.write(Node, LSOutput) method - this could be done
through Channels.newOutputStream(WritableByteChannel). You would
need to filter the close() of the returned OutputStream so you could
invoke FileChannel.force(true) later.
Using RandomAccessFile you could also try constructing it with "rws"
mode [1]:
RandomAccessFile f = new RandomAccessFile("...", "rws");
FileChannel channel = f.getChannel();
OutputStream out = Channels.newOutputStream(channel);
// Do serialize to out.
f.close();
I haven't tested any of the above but it may help.
[1]
<http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html#RandomAccessFile(java.io.File,%20java.lang.String)>
--
Stanimir
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]