question: @ Override public void writeEndDocument ( ) throws XMLStreamException { log . log ( Level . FINE , "writeEndDocument()" ) ; while ( current . getElement ( ) != null ) { writeEndElement ( ) ; } try { WbXmlEncoder encoder = new WbXmlEncoder ( stream , doc , encoderType ) ; encoder . encode ( ) ; encoded = true ; } catch ( IOException e ) { throw new XMLStreamException ( "Error encoding the WbXML document" , e ) ; } }
target:  Closes any start tags and writes corresponding end tags. In the WBXML  implementation the method also performs the real encoding of the WbXmlDocument object (all the previous staff just construct in memory/Java representation object).