File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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:
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

Joined: Oct 14, 2005
Posts: 18140

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.
I agree. Here's the link:
subject: What type of Reader?
Similar Threads package examples
regarding streams
is this 2 much 2 ask?
what is going to happend if i don't close streams?
resources for