Search code examples
javaandroidinputstream

Is there a simple “tee” filter for Java input streams?


For debugging purposes I would like to dump the content of an input stream into a file while it is processed. The stream is parsed by org.xml.sax.XMLReader which will consume the data.

I would gess one need a filter to archive this and before writing one my self I wanted to ask if there is a ready made version already.

I work on Android.

What I have:

final org.apache.http.HttpEntity responseEntity = response.getEntity ();
final java.io.InputStream content = responseEntity.getContent ();
final java.io.InputStreamReader contentReader =
   new java.io.InputStreamReader (content, "UTF-8");

So I have an java.io.InputStream and an InputStreamReader.


Solution

  • Not quite a ready rolled one, but this might be of interest. There is a TeeOutputStream implementation in the examples.