public static Document readDocument(InputStream in,String encoding) throws IOException, XMLException {
  try {
    InputStreamReader reader=new InputStreamReader(in,encoding);
    InputSource source=new InputSource(new BufferedReader(reader));
    Document document;
    try {
      document=documentBuilder.parse(source);
    }
 catch (    SAXException e) {
      throw new XMLException("readDocument failed",e);
    }
    return document;
  }
  finally {
    in.close();
  }
}

public static Document readDocument ( InputStream in , String encoding ) throws IOException , XMLException { try { InputStreamReader reader = new InputStreamReader ( in , encoding ) ; InputSource source = new InputSource ( new BufferedReader ( reader ) ) ; Document document ; try { document = documentBuilder . parse ( source ) ; } catch ( SAXException e ) { throw new XMLException ( "readDocument failed" , e ) ; } return document ; } finally { in . close ( ) ; } }
creates a document instance from a reader reading an xml input stream .
