File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Adding to an Input Stream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Adding to an Input Stream" Watch "Adding to an Input Stream" New topic
Author

Adding to an Input Stream

Arya
Greenhorn

Joined: Apr 14, 2004
Posts: 3
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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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.


[How To Ask Questions On JavaRanch]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I was thinking of something along these lines, which allow you to concatenate multiple Readers:

[ April 24, 2004: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding to an Input Stream