/** * 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.Close(); } }
/** * 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.Close(); } }
/** * 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.Close(); } if (inpB != null) { inpB.Close(); } } return(matches); }
private void CheckAllDirectoryContents(DirectoryEntry dir) { IEnumerator<Entry> it = dir.Entries; //foreach (Entry entry in dir) while (it.MoveNext()) { Entry entry = it.Current; if (entry is DirectoryEntry) { CheckAllDirectoryContents((DirectoryEntry)entry); } else { DocumentNode doc = (DocumentNode)entry; DocumentInputStream dis = new DocumentInputStream(doc); try { int numBytes = dis.Available(); byte[] data = new byte[numBytes]; dis.Read(data); } finally { dis.Close(); } } } }
public void TestAvailable() { DocumentInputStream ostream = new DocumentInputStream(_workbook_o); DocumentInputStream nstream = new NDocumentInputStream(_workbook_n); Assert.AreEqual(_workbook_size, ostream.Available()); Assert.AreEqual(_workbook_size, nstream.Available()); ostream.Close(); nstream.Close(); try { ostream.Available(); Assert.Fail("Should have caught IOException"); } catch (InvalidOperationException) { // as expected } try { nstream.Available(); Assert.Fail("Should have caught IOException"); } catch (InvalidOperationException) { // as expected } }
public override void Close() { delegate1.Close(); }
/** * 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.Close(); if (inpB != null) inpB.Close(); } return matches; }