/** * Create an InputStream from the specified DocumentEntry * * @param document the DocumentEntry to be read * * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has * been deleted?) */ public DocumentInputStream(DocumentEntry document) { if (!(document is DocumentNode)) { throw new IOException("Cannot open internal document storage"); } DocumentNode documentNode = (DocumentNode)document; DirectoryNode parentNode = (DirectoryNode)document.Parent; if (documentNode.Document != null) { delegate1 = new ODocumentInputStream(document); } else if (parentNode.FileSystem != null) { delegate1 = new ODocumentInputStream(document); } else if (parentNode.NFileSystem != null) { delegate1 = new NDocumentInputStream(document); } else { throw new IOException("No FileSystem bound on the parent, can't read contents"); } }
/** * 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(); } }
/** * 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); }
/** * Create an InputStream from the specified Document * * @param document the Document to be read */ public DocumentInputStream(NPOIFSDocument document) { delegate1 = new NDocumentInputStream(document); }