int c;
while ((c = in.read()) != -1) {
if ('<' == c) {
if (isInsideTag) {
throw new InvalidFormatException("Did not expect < char!");
}
if (buffer.toString().trim().length() > 0) {
handler.characters(buffer.toString().trim());
}
buffer.setLength(0);
isInsideTag = true;
isStartTag = true;
}
buffer.appendCodePoint(c);
if ('/' == c && lastChar == '<') {
isStartTag = false;
}
if ('>' == c) {
if (!isInsideTag) {
throw new InvalidFormatException("Did not expect > char!");
}
if (isStartTag) {
handler.startElement(extractTagName(buffer), getAttributes(buffer));
}
else {
handler.endElement(extractTagName(buffer));
}
buffer.setLength(0);
isInsideTag = false;
}
lastChar = c;
}
if (isInsideTag) {
throw new InvalidFormatException("Did not find matching > char!");
}
}