/** Read the incoming stream until it ends. */ private void readStream() throws Exception { while (!shutdown) { Element doc = reader.parseDocument().getRootElement(); if (doc == null) { // Stop reading the stream since the server has sent an end of stream element and // probably closed the connection return; } Packet packet; String tag = doc.getName(); if ("message".equals(tag)) { packet = new Message(doc); } else if ("presence".equals(tag)) { packet = new Presence(doc); } else if ("iq".equals(tag)) { packet = getIQ(doc); } else { throw new XmlPullParserException("Unknown packet type was read: " + tag); } // Request the component to process the received packet component.processPacket(packet); } }