[jdom-interest] i/o question

John L. Webber - jentro AG John.Webber at jentro.com
Thu Oct 5 00:11:28 PDT 2000


Hi Paul,

Have you tried using piped streams? Something along the lines of the
following:

final StringBuffer buffer = new StringBuffer();
XMLOutputter xmlOut = new XMLOutputter("  ", true);
PipedOutputStream pipedOut = new PipedOutputStream();
PipedInputStream pipedIn = new PipedInputStream(pipedOut);
		
final BufferedReader reader = new BufferedReader(new
InputStreamReader(pipedIn));
Runnable readerThread = new Runnable() {
   public void run() {
      String temp;
      try
      {
         while ( (temp = reader.readLine()) != null)
         {
            buffer.append(temp).append("\n");
         }
      }
      catch (IOException io) {}
   }
};
Thread t = new Thread(readerThread);
t.start();
xmlOut.output(doc, pipedOut);
try
{
   t.join(100);
}
catch(InterruptedException ie) { }
		
pipedOut.flush();
pipedOut.close();
reader.close();
String xmlResult = buffer.toString();

You could simply pass the result to the "reader" class, or pass it the
BufferedReader in its constructor.


John Webber

Paul Madsen wrote:

> 
> I have two classes, one that creates an XML file and another than reads
> the created XML file.
> 
> The only reason I'm using the intermediate physical file is that I
> haven't been able to get the two classes to communicate otherwise.
> I know that SAXBuilder.build() will, in addition to a system ID, will
> also take an InputStream.
> 
> I believe I can get the first calss to create something other than a
> FileOutPut stream.
> 
> Forgive me for asking something as basic as how I patch the two streams
> together but I'm stumped. The helpful advice I've recieved on previous
> posts suggests a forgiving attitude to basic questions.
> 

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jentro AG
John L. Webber, Software Development
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Peter-Henlein-Strasse 28-30, 85540 Haar/Munich, Germany
Tel.:  +49 89 462 385 0     (switchboard)
Tel.:  +49 89 462 385 38    (direct)
Fax:   +49 89 462 385 29
mailto:John.Webber at jentro.com
http://www.jentro.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the jdom-interest mailing list