1

Possible Duplicate:
How can I make a copy of a BufferedReader?

I have a method asking for a Reader as parameter :

public List<String> getURI(Reader reader)

In this method, I need to "duplicate" this reader in order to have two TokenStream (one reader for each of them, but both pointing at the same file, string or whatever) so do some sort of :

Reader reader2 = reader;

Since what I've shown above doesn't work, is there an other way to do it?

Thank you for your help.

Regards,

Bdloul

Community
  • 1
  • 1
Bdloul
  • 882
  • 10
  • 27
  • This doesn't make much sense. Why would you need to copy the reader? Are you trying to maintain two different pointers into the underlying file/resource? – Perception Jan 23 '13 at 03:08

1 Answers1

1

If memory usage is not your concern, read the content out into a String object, and instantiate two StringReader instance based on it.

If memory usage is your concern, read the content out using a relatively small buffer, saving into a temp file, and instantiate readers base on it.

Maybe there are other better ways I am also curious about.

Jerry Tian
  • 3,439
  • 4
  • 27
  • 29