On 3 àÌÉ, 17:34, "Joseph J. Kesselman" <keshlam-nos...@comcast. net>
wrote:
Socket -InputStreamRead er -BufferedReader -InputSource -then
it goes to .parse(InputSou rce)....of the SAX.
What node on this chain can be cloned so I can read the data two
times.....once for the parser, once for my debugging log.
I'd suggest dealing with it at the Java level. Find or write a "wrapper"
reader implementation which saves a copy of the data passing through it
off to a data structure or scratch file for rereading, or perhaps which
writes the data direct to your log as it passes through. Plug that in
somewhere between the InputStreamRead er and the InputSource -- whether
upstream, downstream, or in place of the BufferedReader depends on the
details of how this tee adapter is written.
YES!
I've solved my problem using class RecordingInputS tream that wraps the
InputStream
here is the class source code:
import java.io.ByteArr ayOutputStream;
import java.io.FilterI nputStream;
import java.io.InputSt ream;
import java.io.IOExcep tion;
/**
*
* @author Unknown
*
*/
class RecordingInputS tream extends FilterInputStre am {
protected ByteArrayOutput Stream sink;
RecordingInputS tream(InputStre am in) {
this(in, new ByteArrayOutput Stream());
}
RecordingInputS tream(InputStre am in, ByteArrayOutput Stream sink)
{
super(in);
this.sink = sink;
}
public synchronized int read() throws IOException {
int i = in.read();
sink.write(i);
return i;
}
public synchronized int read(byte[] buf, int off, int len) throws
IOException {
int l = in.read(buf, off, len);
sink.write(buf, off, l);
return l;
}
public synchronized int read(byte[] buf) throws IOException {
return read(buf, 0, buf.length);
}
public synchronized long skip(long len) throws IOException {
long l = 0;
int i = 0;
byte[] buf = new byte[1024];
while (l < len) {
i = read(buf, 0, (int)Math.min(( long)buf.length , len -
l));
if (i == -1) break;
l += i;
}
return l;
}
byte[] getBytes() {
return sink.toByteArra y();
}
void resetSink() {
sink.reset();
}
}