Index: core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java
===================================================================
--- core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java	(revision 2078)
+++ core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java	(working copy)
@@ -44,6 +44,7 @@
 import java.io.OutputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
@@ -344,7 +345,9 @@
                 if (entry.getName().compareTo(DefaultPackageFileName) == 0 || entry.isDirectory()) {
                     continue;
                 } else {
-                    XWikiDocument doc = readFromXML(readFromInputStream(zis));
+                    XWikiDocument doc =
+                        readFromXML(readByteArrayFromInputStream(zis, entry.getSize()));
+
                     try {
                         filter(doc, context);
                         if (documentExistInPackageFile(doc.getFullName(), doc.getLanguage(),
@@ -642,6 +645,18 @@
         return buffer.toString();
     }
 
+    private ByteArrayInputStream readByteArrayFromInputStream(ZipInputStream zin, long size)
+        throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream((size > 0) ? (int) size : 4096);
+        byte[] data = new byte[4096];
+        int Cnt;
+        while ((Cnt = zin.read(data, 0, 4096)) != -1) {
+            baos.write(data, 0, Cnt);
+        }
+        return new ByteArrayInputStream(baos.toByteArray());
+    }
+
     private XWikiDocument readFromXML(String XmlFile) throws XWikiException
     {
         XWikiDocument doc = new com.xpn.xwiki.doc.XWikiDocument();
@@ -653,6 +668,17 @@
         return doc;
     }
 
+    private XWikiDocument readFromXML(InputStream is) throws XWikiException
+    {
+        XWikiDocument doc = new com.xpn.xwiki.doc.XWikiDocument();
+        if (backupPack && withVersions)
+            doc.fromXML(is, true);
+        else {
+            doc.fromXML(is);
+        }
+        return doc;
+    }
+
     private Document ReadZipInfoFile(ZipInputStream zis) throws IOException, DocumentException
     {
         ZipEntry entry;
@@ -799,8 +825,7 @@
             fos.close();
         } catch (ExcludeDocumentException e) {
             log.info("Skip the document " + doc.getFullName());
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             Object[] args = new Object[1];
             args[0] = doc.getFullName();
             throw new XWikiException(XWikiException.MODULE_XWIKI_DOC,
@@ -930,7 +955,7 @@
                     filename += "." + doc.getLanguage();
                 }
                 File docfile = new File(space, filename);
-                doc = readFromXML(readFromInputStream(new FileInputStream(docfile)));
+                doc = readFromXML(new FileInputStream(docfile));
                 if (doc == null) {
                     if (log.isErrorEnabled()) {
                         log.info("Package readFrom XML read null doc for " + docName +
Index: core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	(revision 2078)
+++ core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	(working copy)
@@ -68,6 +68,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.ref.SoftReference;
@@ -2149,6 +2150,11 @@
         fromXML(xml, false);
     }
 
+    public void fromXML(InputStream is) throws XWikiException
+    {
+        fromXML(is, false);
+    }
+
     public void fromXML(String xml, boolean withArchive) throws XWikiException
     {
         SAXReader reader = new SAXReader();
@@ -2162,6 +2168,31 @@
                 XWikiException.ERROR_DOC_XML_PARSING, "Error parsing xml", e, null);
         }
 
+        fromXML(domdoc, withArchive);
+    }
+
+    public void fromXML(InputStream in, boolean withArchive) throws XWikiException
+    {
+        SAXReader reader = new SAXReader();
+        Document domdoc;
+
+        try {
+            domdoc = reader.read(in);
+        } catch (DocumentException e) {
+            log.error("Caught a Document Exception from SAXParser.");
+            throw new XWikiException(XWikiException.MODULE_XWIKI_DOC,
+                XWikiException.ERROR_DOC_XML_PARSING,
+                "Error parsing xml",
+                e,
+                null);
+        }
+
+        fromXML(domdoc, withArchive);
+    }
+
+    public void fromXML(Document domdoc, boolean withArchive) throws XWikiException
+    {
+
         Element docel = domdoc.getRootElement();
         setName(getElement(docel, "name"));
         setSpace(getElement(docel, "web"));
