Use switch/case instead if/else-if in parsePackets()
Don't check for END_DOCUMENT parsePackets()

instead use the event switch/case and log a warning if this ever
happens, as it's likely a programming error.