Example #1
0
        /**
         * Copies an Entry into a target POIFS directory, recursively
         */
        public static void CopyNodeRecursively(Entry entry, DirectoryEntry target)
        {
            // System.err.println("copyNodeRecursively called with "+entry.getName()+
            // ","+target.getName());
            DirectoryEntry newTarget = null;

            if (entry.IsDirectoryEntry)
            {
                DirectoryEntry dirEntry = (DirectoryEntry)entry;
                newTarget = target.CreateDirectory(entry.Name);
                newTarget.StorageClsid = (dirEntry.StorageClsid);
                IEnumerator <Entry> entries = dirEntry.Entries;

                while (entries.MoveNext())
                {
                    CopyNodeRecursively((Entry)entries.Current, newTarget);
                }
            }
            else
            {
                DocumentEntry       dentry  = (DocumentEntry)entry;
                DocumentInputStream dstream = new DocumentInputStream(dentry);
                target.CreateDocument(dentry.Name, dstream);
                dstream.Dispose();
            }
        }
Example #2
0
        /**
         * Checks to see if two Documents have the same name
         *  and the same contents. (Their parent directories are
         *  not checked)
         */
        public static bool AreDocumentsIdentical(DocumentEntry docA, DocumentEntry docB)
        {
            if (!docA.Name.Equals(docB.Name))
            {
                // Names don't match, not the same
                return(false);
            }
            if (docA.Size != docB.Size)
            {
                // Wrong sizes, can't have the same contents
                return(false);
            }

            bool matches = true;
            DocumentInputStream inpA = null, inpB = null;

            try
            {
                inpA = new DocumentInputStream(docA);
                inpB = new DocumentInputStream(docB);

                int readA, readB;
                do
                {
                    readA = inpA.Read();
                    readB = inpB.Read();
                    if (readA != readB)
                    {
                        matches = false;
                        break;
                    }
                } while (readA != -1 && readB != -1);
            }
            finally
            {
                if (inpA != null)
                {
                    inpA.Dispose();
                }
                if (inpB != null)
                {
                    inpB.Dispose();
                }
            }

            return(matches);
        }
Example #3
0
 protected override void Dispose(bool disposing)
 {
     delegate1.Dispose();
 }