aspose file tools*
The moose likes Java in General and the fly likes What type of Reader? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What type of Reader?" Watch "What type of Reader?" New topic
Author

What type of Reader?

Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
I have an application that generates an xml file on the fly. The xml strings are held in an arraylist, one line per element. When I print it out to a page, I simply get each successive line and write it to a file. I would like to be able to convert it to a graph without first having to write it to a file.

The class I am using to convert to a graph uses a reader, but I am not sure which type of reader to use. There is a chart on this page:
http://java.sun.com/developer/technicalArticles/Streams/ProgIOStreams/
So it looks to me like I need to use a String Reader? Or is there another way to do this that I had not considered?
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
Just to provide at least one solution (admittedly not very elegant). I concatenated all of the lines of text into one giant string, and then used the StringReader class to feed it to the XML parser.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

If you are looking for something elegant (and if you think your solution is going to blow out your memory) then you might consider a SequenceInputStream. I liked the idea so much I decided to write it myself. First you need this helper class:Then you use that class like this:
[ April 04, 2007: Message edited by: Paul Clapham ]
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
Thank you very much. Shortly after I made the post, I tried a sequence that returned nearly 250,000 nodes. My computer didn't like that at all. I let it run for about 15 minutes to see if it could handle it before I gave up. I'll give your solution a whirl and see if it can handle the data.

Best Regards.
 
 
subject: What type of Reader?