title: Premature end of file parsing XML
body: <p>I use this method to validate the xml file that stores some config info:</p>
  
  <pre><code>public static boolean isXmlFileWellFormed(File xmlFile) {
      logger.log(Level.INFO, "isXmlFileWellFormed({0})", xmlFile);
      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder;
      try {
          builder = builderFactory.newDocumentBuilder();
          builder.parse(xmlFile);
          return true; // document well formed
      } catch (Throwable ex) {
          logger.log(Level.WARNING, "Xml file is not well-formed: {0}", ex);
          try {
              FileUtils.streamToFile(new FileInputStream(xmlFile), "c:\\backup.xml");
          } catch (IOException ex1) {
              logger.log(Level.WARNING, "backup not created");
          }
      }
      return false;
  }
  </code></pre>
  
  <p>it validates the xml file well, it looks like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;mountedFolders&gt;
  
  &lt;folder path="C:\tmp\prezentacka\" recursively="false"&gt;
          &lt;document key="1636_0001_pdf_1.png;539777;1338204039646"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;document key="faktura.pdf;1102305;1336552599405"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;document key="prva strana_1361268270589.JPEG;276888;1361269977428"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;/folder&gt;
  &lt;folder path="C:\tmp\one2\" recursively="false"&gt;
          &lt;document key="1636_0001.pdf;280700;1336569165030"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;document key="1636_0001_pdf_1.png;539777;1338204039646"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;document key="1636_0001_pdf_2.png;565609;1338204041562"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;document key="1637_0001.pdf;121031;1336569168739"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;document key="faktura.pdf;1102305;1336552599405"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;/folder&gt;
  &lt;folder path="C:\tmp\" recursively="false"&gt;
          &lt;document key="faktura1.pdf;637590;1340007249059"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;document key="LicZmluva.pdf;41164;1340016186796"&gt;
              &lt;state&gt;NEW&lt;/state&gt;
          &lt;/document&gt;
      &lt;/folder&gt;
  &lt;/mountedFolders&gt;
  </code></pre>
  
  <p>meybe its not totaly well formed but it should be valid. Actualy, this xml is the backup.xml saved after the parsing method crashes in catch block of code with error</p>
  
  <pre><code>[INFO] stderr.run: [Fatal Error] .mounted:1:1: Premature end of file.
  [WARNING] XmlUtils.isXmlFileWellFormed: Xml file is not well-formed: 
  </code></pre>
  
  <p>Can it somehow relate to threads?
  thanks everyone</p>
  
  <p><strong>UPDATE</strong>
  I created error handler for document builder but it says again </p>
  
  <blockquote>
    <p>fatal error: premature end of file</p>
  </blockquote>