From: Ian Shef on 18 Mar 2010 20:40 EJP <esmond.not.pitt(a)not.bigpond.com> wrote in news:TGmon.13637$pv.10376 @news-server.bigpond.net.au: > On 17/03/2010 11:59 PM, Dennis wrote: >> >> public class ForkedInputStream extends InputStream { > > == java.io.SequenceInputStream, with more bugs I don't think so. You might be correct about the bugs, but not about the equivalence. From the Javadocs: "A SequenceInputStream represents the logical concatenation of other input streams." A SequenceInputStream performs concatenation. A ForkedInputStream provides what I would call a Tee. It provides input, and also echoes that input to the designated OutputStream. -------- The original poster might want to look at http://commons.apache.org/io/apidocs/org/apache/commons/io/input/TeeInputStre am.html for another implementation of this idea. It has more features and possibly fewer bugs. The sources are open, for some definition of "open". See http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/comm ons/io/input/TeeInputStream.java?view=markup
From: Mike Schilling on 18 Mar 2010 20:42 Dennis wrote: > Dear all, > > This has been puzzling me all morning: There is reasonable elegant > way (see example below) to log InputStreams and OutputStreams, > without consuming the streams. However, I cannot find any reference > to it or a good implementation of it anywhere. I tested it and it > seems to work, but I have the nagging idea that I'm missing > something, or I did miss all the references to it on the internet. I'd probably extend FilterInputStream and just call super() for all the processing of the "main" stream e,g, public class TeeInputStream extends FilterInputStream { private OutputStream m_tee; public TeeInputStream(InputStream in, OutputStream fork) { super(in); } public int read() throws IOException { int c = super.read(); if (b == -1) m_tee.flush(); else m_tee.write(c); } public void close() throws IOException { super.close(); m_tee.close(); } // etc. }
From: EJP on 18 Mar 2010 21:17 On 18/03/2010 8:49 PM, EJP wrote: > == java.io.SequenceInputStream, with more bugs Sorry, I am crazy, it is actually more like tee(1). I wrote a TeeInputStream at some point about 10 years ago, wonder where it is.
From: dennis on 20 Mar 2010 13:44 >The original poster might want to look at >http://commons.apache.org/io/apidocs/org/apache/commons/io/input/TeeInputStre >am.html >for another implementation of this idea. It has more features and possibly >fewer bugs. Hi Ian, Thanks for the reference. This was helpfull. At least now I know it has been done before (and with no unexpected side effects). I'm not sure yet if I want to use that one directly, or use my own implementation: - One they are using ProxyInputStream which possibly allows for seek(),mark() and reset() of the underlying stream and this could mean part of the output would not be written multiple times or not at all. You either have to handle that or at least mark the output that there was a part not written or written multiple times. Especially when you use it for logging or storing xml-requests - The license issue. If I use mine it will be done under the modified BSD-license so no restrictions to future users. Kind regards, Dennis
From: dennis on 20 Mar 2010 13:49 Hi Mike, Thanks for the feedback. I looked into FilterInputStream, but did not want to use it while the underlying stream might support seek(), mark() and reset() and this will prevent data being written to the output or data being written multiple times. You either have to handle that or at least mark the output that there was a part not written or writtenmore then once. Especially when you use it for logging or storing xml-requests. Kind regards, Dennis..
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Applet UpCall from JS Event - Which Thread? Next: eclipselink @table annotation |