I’m implementing a syntax reader as a spin-off from a homework assignment, and I’m reading an XML file one character at a time. My goal is to take the code that I passed the lab assignment with, and improve the structure and design.
I have a SyntaxReader that inherits from PushbackReader, which has some extra methods like readAndExpect(char c), trimWhitespace() and readUntilChar(char c). Then I have an XMLSyntaxReader that inherits from SyntaxReader and adds functionality like readAttribute() and readNode() (the latter being recursive for children in the tree…).
I have basically just taken the working code from my lab assignment and pasted it into the appropriate places in this approach. However, when I try to read the first child, I’m getting an IOException: Pushback buffer overflow that I can’t figure out.
This is the beginning of my XML file:
<Biosfar namn="Liv">ar allt som fortplantar sig
<Rike namn="Vaxter"> etc...
I have debugged and watched the syntax readers successfully read all the way through <R at the beginning of the child tag. At that point, the XMLSyntaxReader confirms that it is a child tag, unreads the two last characters (R and <, in that order) and calls on readNode() to parse the child node. The exception occurs when I try to unread <.
In the debugger, I have also verified that the private pos variable of the PushbackReader is really set to 0, but I can’t figure out why. I’ve parsed a full line of text – why don’t those characters still count?
I’d post my code, but it’s quite lengthy and as the same worked before I’m not sure my exact implementation is relevant. If it is, please point to someplace I can upload snippets, and I’ll share all the code.
Isn’t the default size of the PushbackReader buffer only 1? That would cause this problem when you push the second character. What happens if you increase the size of the buffer?