title: Filter \n character from inputstream
body: <p>I trying to parse xml from an inputstream using the sax parser. The inputstream get incoming xml continously from a socket. '\n' is used as a delimiter between xml data. This is how the xml would look like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;response processor="header" callback="comheader"&gt;
      &lt;properties&gt;
          &lt;timezone&gt;Asia%2FBeirut&lt;/timezone&gt;
          &lt;rawoffset&gt;7200000&lt;/rawoffset&gt;
          &lt;to_date&gt;1319256000000&lt;/to_date&gt;
          &lt;dstrawoffset&gt;10800000&lt;/dstrawoffset&gt;
      &lt;/properties&gt;
  &lt;/response&gt;
  \n
  &lt;event type="progress" time="1317788744214"&gt;
      &lt;param key="callback"&gt;todayactions&lt;/param&gt;
      &lt;param key="percent"&gt;10&lt;/param&gt;
      &lt;param key="msg"&gt;MAPPING&lt;/param&gt;
  &lt;/event&gt;
  &lt;event type="progress" time="1317788744216"&gt;
      &lt;param key="callback"&gt;todayactions&lt;/param&gt;
      &lt;param key="percent"&gt;20&lt;/param&gt;&lt;param key="msg"&gt;MAPPING&lt;/param&gt;
  &lt;/event&gt;
  \n
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;response processor="header" callback="comheader"&gt;
      &lt;properties&gt;
          &lt;timezone&gt;Asia%2FBeirut&lt;/timezone&gt;
          &lt;rawoffset&gt;7200000&lt;/rawoffset&gt;
          &lt;to_date&gt;1319256000000&lt;/to_date&gt;
          &lt;dstrawoffset&gt;10800000&lt;/dstrawoffset&gt;
      &lt;/properties&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p>This worked perfectly for the our iphone project as we took the characters upto \n and stored that in a string and used the dom parser.</p>
  
  <p>But when I tried to do this for the android, string was not an option as it gave us OutOfMemory exception. So we set the inputstream directly to the SaxParser it works until the \n character, after that it gives us the exception</p>
  
  <blockquote>
    <p>org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column
    0: junk after document element</p>
  </blockquote>
  
  <p><strong>So I tried to filter the inputstream to skip the '\n' character</strong>. I created a FilterStreamReader but I was not successful, it seems my read function isn't doing the job. Here is my code.</p>
  
  <pre><code>public class FilterStreamReader extends InputStreamReader {
      public FilterStreamReader(InputStream in, String enc)
              throws UnsupportedEncodingException {
          super(in, enc);
      }
  
      @Override
      public int read(char[] cbuf, int off, int len) throws IOException {
          int read = super.read(cbuf, off, len);
          Log.e("Reader",Character.toString((char)read));
          if (read == -1) {
              return -1;
          }
  
          int pos = off - 1;
          for (int readPos = off; readPos &lt; off + read; readPos++) {
              if (read == '\n') {
                  pos++;
              } else {                
                  continue;
              }
              if (pos &lt; readPos) {
                  cbuf[pos] = cbuf[readPos];
              }
          }
          return pos - off + 1;
  }
  </code></pre>
  
  <p><strong>Can someone help me filter the \n of an inputstream?</strong></p>
  
  <p><strong>Edit</strong>
  Based on what graham  said I was able to parse the whole data by removing all the doc types and adding my own start and end tag. So Im not really sure that my problem is not filtering '\n' alone. How can you parse xml that keeps coming like this? </p>