• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What type of Reader?

 
Chad Clites
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20161
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic