Re: problem with reading stream
On Sep 21, 1:34 am, "Durango@google" <El_Dura...@yahoo.com> wrote:
Hello, I am trying to read a stream from a URL into a Inputsource and
pass that to a DOM parser.
The URL links to a RSS file and I am able to successfully read this.
The problem I am having is that, the data that the stream reads causes
the parser to throw errors.
This is because the RSS stream starts with a newline character. If
the newline character is removed than the parser works fine.
I was able to read the RSS stream and write it to a file omitting the
newline character.
After that I read the file stream into the Inputsource and passed it
to the Dom parser.
This worked fine, however I do not want to save it to a file, rather I
would like to know if there is
a way to manipulate the stream before passing it to the Inputsource
before it gets passed to the parser?
Anyone have any suggestions for the issue I am facing?
First - it is completely legal for an XML file to begin with
whitespace, comments, processing instructions, or a tag - so (in the
absence of an example) I have to suppose that your RSS parser is a bit
buggy.
However, until the bug you file is fixed, you can probably work around
it a few ways: you can use a BufferedInputStream around the base input
stream in combination with the mark method to do this:
1. Mark in preparation for reading one byte.
2. Read a byte.
3. If the byte matches one of the whitespace tokens, go to 1.
4. reset() to "un-read" the last byte.
After all of this, the buffered stream will be at a point where the
next reads will begin at the first non-whitespace byte. You might
want to consider using a Reader rather than an InputStream for this,
so that you get character-oriented rather than byte-oriented
behaviour, though.
What does feedvalidator say about the RSS file at the URL? It's
possible the RSS resource itself is defective, which should be
reported (with a feedvalidator link for emphasis) to whoever's
publishing the feed.
-o