Example #1
0
        /**
         * Performs the check described in {@link #TestReCreate()} for a single
         * POI filesystem.
         *
         * @param f the POI filesystem to check
         */
        private void TestRecreate(FileStream f)
        {
            Console.WriteLine("Recreating file \"" + f + "\"");

            /* Read the POI filesystem's property Set streams: */
            POIFile[] psf1 = Util.ReadPropertySets(f);

            /* Create a new POI filesystem containing the origin file's
             * property Set streams: */
            FileInfo   fi   = new FileInfo(f.Name);
            FileStream copy = File.Create(testContextInstance.TestDir + "\\" + fi.Name);
            //copy.deleteOnExit();
            FileStream      out1  = copy;
            POIFSFileSystem poiFs = new POIFSFileSystem();

            for (int i = 0; i < psf1.Length; i++)
            {
                Stream in1 =
                    new MemoryStream(psf1[i].GetBytes());
                PropertySet        psIn     = PropertySetFactory.Create(in1);
                MutablePropertySet psOut    = new MutablePropertySet(psIn);
                MemoryStream       psStream =
                    new MemoryStream();
                psOut.Write(psStream);
                psStream.Close();
                byte[] streamData = psStream.ToArray();
                poiFs.CreateDocument(new MemoryStream(streamData),
                                     psf1[i].GetName());
                poiFs.WriteFileSystem(out1);
            }

            /* Read the property Set streams from the POI filesystem just
             * Created. */
            POIFile[] psf2 = Util.ReadPropertySets(copy);
            for (int i = 0; i < psf2.Length; i++)
            {
                byte[]      bytes1 = psf1[i].GetBytes();
                byte[]      bytes2 = psf2[i].GetBytes();
                Stream      in1    = new MemoryStream(bytes1);
                Stream      in2    = new MemoryStream(bytes2);
                PropertySet ps1    = PropertySetFactory.Create(in1);
                PropertySet ps2    = PropertySetFactory.Create(in2);

                /* Compare the property Set stream with the corresponding one
                 * from the origin file and check whether they are equal. */
                Assert.IsTrue(ps1.Equals(ps2));
            }
            out1.Close();
        }