Can somebody provide a source of
public class CopyingInputStreamReader extends InputStreamReader {
public CopyingInputStreamReader(InputStream is, OutputStream copyStream) {
.....
The implementation should copy whatever got read to output stream. I have my implementation, but my HD crashed, so I need to recover it. Please respond in next 5 minutes, otherwise I will figure ot myself.
Personally I wouldn’t do this at the reader level. I would write an
InputStreamwhich overrides all the methods methods fromInputStream, delegating to the input stream that’s been passed to the constructor and writes to the output stream after each read, before returning the data to the caller. For example:The reason I wouldn’t make at extend
InputStreamReaderis that the results of all thereadoperations would be text data – which you’d then need to write to yourOutputStreamsomehow…Of course, if you really want to convert from one encoding to another, it would be worth extending
Readerinstead ofInputStream, take anotherReaderto delegate to and aWriterto write to. Again, then you stay within one realm (text) instead of being part of the conversion yourself.EDIT: It strikes me that I forgot to mention you also need to override the non-read methods to either just delegate directly to the input stream, or throw an exception. (For example, you probably don’t want to support mark/reset.)