title: Error while parsing XML file with StAx
body: <p>I wrote a xml parser with StAx that I use to parse XML streams received from the server.Here is my code : </p>
  
  <pre><code>private Map&lt;String, IUnitaryAction&gt; parse(InputStream is) throws XMLStreamException {
  
      XMLInputFactory factory = XMLInputFactory.newInstance();
      XMLStreamReader reader = factory.createXMLStreamReader(is);
      boolean action = false;
      Map&lt;String, IUnitaryAction&gt; actionsMap = new HashMap&lt;String, IUnitaryAction&gt;();
  
      while(reader.hasNext()){
          int type = reader.next();
          switch(type){
          case XMLStreamReader.START_ELEMENT :
              action = reader.getLocalName().equals("action-description");
              break;
  
          case XMLStreamReader.CHARACTERS :
              if( action ){
                  String act = reader.getText();
                  System.out.println("Action trouvées " + act);
  
                  String[] praxiscmd = act.split("_");
                  if("CREATE".equals(praxiscmd[0])){
                      Create c = new Create(praxiscmd[1], praxiscmd[2], null);
                      actionsMap.put(praxiscmd[1], c);
                  } else if("DELETE".equals(praxiscmd[0])){
                      Delete d = new Delete(praxiscmd[1],praxiscmd[2], null);
                      actionsMap.put(praxiscmd[1], d);
                  } else if ("ADDPROPERTY".equals(praxiscmd[0])) {
                      AddProperty ap = new AddProperty(praxiscmd[1],
                              praxiscmd[2], praxiscmd[3], null);
                      actionsMap.put(praxiscmd[1], ap);
                  } else if ("ADDREFERENCE".equals(praxiscmd[0])) {
                      AddReference ar = new AddReference(praxiscmd[1],
                              praxiscmd[2], praxiscmd[3], null);
                      actionsMap.put(praxiscmd[1], ar);
                  } else if ("REMPROPERTY".equals(praxiscmd[0])) {
                      RemProperty rp = new RemProperty(praxiscmd[1],
                              praxiscmd[2], praxiscmd[3], null);
                      actionsMap.put(praxiscmd[1], rp);
                  } else if ("REMREFERENCE".equals(praxiscmd[0])) {
                      RemReference rr = new RemReference(praxiscmd[1],
                              praxiscmd[2], praxiscmd[3], null);
                      actionsMap.put(praxiscmd[1], rr);
                  }
              }
          }
      }
  </code></pre>
  
  <p>I get this error on the line : <code>int type = reader.next()</code>: </p>
  
  <pre><code> javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
  Message: Premature end of file.
      at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:584)
      at fr.lip6.graphelex.TelexImpl.parse(TelexImpl.java:147)
      at fr.lip6.graphelex.TelexImpl.sendHttpRequest(TelexImpl.java:264)
      at fr.lip6.graphelex.TelexImpl.schedules(TelexImpl.java:116)
      at fr.lip6.graphelex.MapperImpl.send(MapperImpl.java:92)
      at fr.lip6.graphelex.GraphElexAgent.executeCycle(GraphElexAgent.java:81)
      at praxis.guidance.agent.Agent.run(Agent.java:71)
      at java.lang.Thread.run(Thread.java:636)
  </code></pre>
  
  <p>I don't understand what is the problem since i use the same parser for another case and it perfectly work. 
  Here is an example of XML streams I received from a server :</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
    &lt;responses&gt;
     &lt;executed-commands&gt;
        &lt;command&gt;&lt;name&gt;GETLASTSCEDULES&lt;/name&gt;
        &lt;status-code&gt;200&lt;/status-code&gt;
        &lt;description&gt;last schedule returned&lt;/description&gt;
        &lt;/command&gt;
       &lt;/executed-commands&gt;
         &lt;schedules&gt;&lt;schedule&gt;&lt;schedule-id&gt;0&lt;/schedule-id&gt;
         &lt;doc-id&gt;/telexDocuments/doc.dox&lt;/doc-id&gt;
         &lt;actions&gt;
           &lt;action&gt;
            &lt;action-description&gt;CREATE__8VtAMXv4EeCwaM2v2VqUyg_Model&lt;/action-description&gt;  
           &lt;action-id&gt;/telexDocuments/doc.dox:Peer#server2:hephaistos:0:15&lt;/action-id&gt;
          &lt;/action&gt;
        &lt;/actions&gt;
        &lt;non-actions/&gt;&lt;/schedule&gt;&lt;/schedules&gt;
        &lt;get-constraints/&gt;
  &lt;/responses&gt;
  </code></pre>
  
  <p>Can someone give some advice ? </p>
  
  <p><strong>EDIT</strong> :
  I may find the answer to my question. The problem was when I have received the answer from the server as InputStream, I <strike>read</strike> parse it. As you may know, in Java, once an InputStream is <strike>read</strike> parsed, it is close automatically. Things sometime we forgot. Thanks for the <a href="http://download.oracle.com/javase/6/docs/api/org/xml/sax/InputSource.html" rel="noreferrer">documentation</a></p>