Пример #1
0
        public void TestCopyRecursively()
        {
            POIFSFileSystem fsD  = new POIFSFileSystem();
            POIFSFileSystem fs   = new POIFSFileSystem();
            DirectoryEntry  dirA = fs.CreateDirectory("DirA");
            DirectoryEntry  dirB = fs.CreateDirectory("DirB");

            DocumentEntry entryR  = fs.CreateDocument(new ByteArrayInputStream(dataSmallA), "EntryRoot");
            DocumentEntry entryA1 = dirA.CreateDocument("EntryA1", new ByteArrayInputStream(dataSmallA));
            DocumentEntry entryA2 = dirA.CreateDocument("EntryA2", new ByteArrayInputStream(dataSmallB));

            // Copy docs
            Assert.AreEqual(0, fsD.Root.EntryCount);
            EntryUtils.CopyNodeRecursively(entryR, fsD.Root);

            Assert.AreEqual(1, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));

            EntryUtils.CopyNodeRecursively(entryA1, fsD.Root);
            Assert.AreEqual(2, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));

            EntryUtils.CopyNodeRecursively(entryA2, fsD.Root);
            Assert.AreEqual(3, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("EntryRoot"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA1"));
            Assert.IsNotNull(fsD.Root.GetEntry("EntryA2"));

            // Copy directories
            fsD = new POIFSFileSystem();
            Assert.AreEqual(0, fsD.Root.EntryCount);

            EntryUtils.CopyNodeRecursively(dirB, fsD.Root);
            Assert.AreEqual(1, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);

            EntryUtils.CopyNodeRecursively(dirA, fsD.Root);
            Assert.AreEqual(2, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirB"));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry("DirA"));
            Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);

            // Copy the whole lot
            fsD = new POIFSFileSystem();
            Assert.AreEqual(0, fsD.Root.EntryCount);

            EntryUtils.CopyNodes(fs, fsD, new List <String>());
            Assert.AreEqual(3, fsD.Root.EntryCount);
            Assert.IsNotNull(fsD.Root.GetEntry(dirA.Name));
            Assert.IsNotNull(fsD.Root.GetEntry(dirB.Name));
            Assert.IsNotNull(fsD.Root.GetEntry(entryR.Name));
            Assert.AreEqual(0, ((DirectoryEntry)fsD.Root.GetEntry("DirB")).EntryCount);
            Assert.AreEqual(2, ((DirectoryEntry)fsD.Root.GetEntry("DirA")).EntryCount);
        }
Пример #2
0
        private void Write(NPOIFSFileSystem fs)
        {
            // For tracking what we've written out, so far
            List <String> excepts = new List <String>(1);

            // Write out our HPFS properties, with any changes
            WriteProperties(fs, excepts);

            // Copy over everything else unchanged
            EntryUtils.CopyNodes(directory, fs.Root, excepts);

            // Caller will save the resultant POIFSFileSystem to the stream/file
        }
Пример #3
0
        /**
         * Write out, with any properties changes, but nothing else
         */
        public override void Write(Stream out1)
        {
            POIFSFileSystem fs = new POIFSFileSystem();

            // For tracking what we've written out, so far
            List <String> excepts = new List <String>(1);

            // Write out our HPFS properties, with any changes
            WriteProperties(fs, excepts);

            // Copy over everything else unchanged
            EntryUtils.CopyNodes(directory, fs.Root, excepts);

            // Save the resultant POIFSFileSystem to the output stream
            fs.WriteFileSystem(out1);
        }
Пример #4
0
        public void TestHeavilyNestedReWrite()
        {
            foreach (DirectoryNode root in openSSSample("ex42570-20305.xls", false))
            {
                // Record the structure
                Dictionary <String, int> entries = new Dictionary <String, int>();
                fetchSizes("/", root, entries);

                // Prepare to copy
                DirectoryNode dest;
                if (root.NFileSystem != null)
                {
                    dest = (new NPOIFSFileSystem()).Root;
                }
                else
                {
                    dest = (new OPOIFSFileSystem()).Root;
                }

                // Copy over
                EntryUtils.CopyNodes(root, dest);

                // Re-load, always as NPOIFS
                MemoryStream baos = new MemoryStream();
                if (root.NFileSystem != null)
                {
                    root.NFileSystem.WriteFileSystem(baos);
                }
                else
                {
                    root.OFileSystem.WriteFileSystem(baos);
                }
                NPOIFSFileSystem read = new NPOIFSFileSystem(
                    new MemoryStream(baos.ToArray()));

                // Check the structure matches
                CheckSizes("/", read.Root, entries);
            }
        }
Пример #5
0
        public void NPOIFSReadCopyWritePOIFSRead()
        {
            FileStream       testFile = POIDataSamples.GetSpreadSheetInstance().GetFile("Simple.xls");
            NPOIFSFileSystem src      = new NPOIFSFileSystem(testFile);

            byte[] wbDataExp = IOUtils.ToByteArray(src.CreateDocumentInputStream("Workbook"));

            NPOIFSFileSystem nfs = new NPOIFSFileSystem();

            EntryUtils.CopyNodes(src.Root, nfs.Root);
            src.Close();

            MemoryStream bos = new MemoryStream();

            nfs.WriteFileSystem(bos);
            nfs.Close();

            POIFSFileSystem pfs = new POIFSFileSystem(new MemoryStream(bos.ToArray()));

            byte[] wbDataAct = IOUtils.ToByteArray(pfs.CreateDocumentInputStream("Workbook"));

            Assert.That(wbDataExp, new EqualConstraint(wbDataAct));
        }
Пример #6
0
 protected void CopyNodes(DirectoryNode sourceRoot,
                          DirectoryNode targetRoot, List <string> excepts)
 {
     EntryUtils.CopyNodes(sourceRoot, targetRoot, excepts);
 }
Пример #7
0
 protected void CopyNodes(POIFSFileSystem source, POIFSFileSystem target,
                          List <string> excepts)
 {
     EntryUtils.CopyNodes(source, target, excepts);
 }