Added additional failure checks for startDocument() return value, and empty filesize() on endDocument().