Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding to an Input Stream

 
Arya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a stream of a file in the form of a Reader. I pass this Reader to a 'tool' that does something.
What I want to do is this:
After the stream has been obtained from a file I want to add something to the stream and still be able to pass the Reader to the 'tool' for processing.
Basically I want to add to the content of the file 'after' it has been and read(ie a Reader has been obtained) and I also want it to be in the form of a Reader so that it can be passed to the 'tool'.
Can anyone of you please suggest something on this ?
Thanks in advance.
Arya
 
Joe Ess
Bartender
Pie
Posts: 9259
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest thing to do would be to read your file into a String object, concatenate the String object with whatever you want to add, create a java.io.StringReader instance from the combined String and pass that StringReader to your tool.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like we ought to be able to cobble something together to work like a Unix or DOS filter. You should be able to chain these things together. Has anybody made a generalized solution to this? Maybe it would require putting each stage on a thread? I thought about it for about 10 minutes once and then went and had some chocolate instead.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking of something along these lines, which allow you to concatenate multiple Readers:

[ April 24, 2004: Message edited by: Jim Yingst ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic