/** * 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); }
/** * <p>Creates the most specific {@link PropertySet} from an entry * in the specified POIFS Directory. This is preferrably a {@link * DocumentSummaryInformation} or a {@link SummaryInformation}. If * the specified entry does not contain a property Set stream, an * exception is thrown. If no entry is found with the given name, * an exception is thrown.</p> * * @param dir The directory to find the PropertySet in * @param name The name of the entry Containing the PropertySet * @return The Created {@link PropertySet}. * @if there is no entry with that name * @if the stream does not * contain a property Set. * @if some I/O problem occurs. * @exception EncoderFallbackException if the specified codepage is not * supported. */ public static PropertySet Create(DirectoryEntry dir, String name) { Stream inp = null; try { DocumentEntry entry = (DocumentEntry)dir.GetEntry(name); inp = new DocumentInputStream(entry); try { return Create(inp); } catch (MarkUnsupportedException e) { return null; } } finally { if (inp != null) inp.Close(); } }
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 override void Close() { delegate1.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 void SetUp() { bout = new MemoryStream(); poifs = new POIFSFileSystem(); dir = poifs.Root; dsi = null; try { DocumentEntry dsiEntry = (DocumentEntry) dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(dsiEntry); PropertySet ps = new PropertySet(dis); dis.Close(); dsi = new DocumentSummaryInformation(ps); } catch (FileNotFoundException) { /* There is no document summary information yet. We have to Create a * new one. */ dsi = PropertySetFactory.CreateDocumentSummaryInformation(); Assert.IsNotNull(dsi); } catch (IOException) { ////e.printStackTrace(); Assert.Fail(); } catch (NoPropertySetStreamException) { ////e.printStackTrace(); Assert.Fail(); } catch (MarkUnsupportedException) { ////e.printStackTrace(); Assert.Fail(); } catch (UnexpectedPropertySetTypeException) { ////e.printStackTrace(); Assert.Fail(); } Assert.IsNotNull(dsi); try { DocumentEntry dsiEntry = (DocumentEntry) dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(dsiEntry); PropertySet ps = new PropertySet(dis); dis.Close(); si = new SummaryInformation(ps); } catch (FileNotFoundException) { /* There is no document summary information yet. We have to Create a * new one. */ si = PropertySetFactory.CreateSummaryInformation(); Assert.IsNotNull(si); } catch (IOException) { ////e.printStackTrace(); Assert.Fail(); } catch (NoPropertySetStreamException) { ////e.printStackTrace(); Assert.Fail(); } catch (MarkUnsupportedException) { ////e.printStackTrace(); Assert.Fail(); } catch (UnexpectedPropertySetTypeException) { ////e.printStackTrace(); Assert.Fail(); } Assert.IsNotNull(dsi); }
/** * Closes the MemoryStream and Reads it into a MemoryStream. * When finished writing information this method is used in the Tests to * start Reading from the Created document and then the see if the results match. * */ private void CloseAndReOpen() { try { dsi.Write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME); si.Write(dir, SummaryInformation.DEFAULT_STREAM_NAME); } catch (WritingNotSupportedException) { ////e.printStackTrace(); Assert.Fail(); } catch (IOException) { ////e.printStackTrace(); Assert.Fail(); } si = null; dsi = null; try { poifs.WriteFileSystem(bout); bout.Flush(); } catch (IOException) { ////e.printStackTrace(); Assert.Fail(); } Stream is1 = new MemoryStream(bout.ToArray()); Assert.IsNotNull(is1); poifs = null; try { poifs = new POIFSFileSystem(is1); } catch (IOException) { ////e.printStackTrace(); Assert.Fail(); } try { is1.Close(); } catch (IOException) { ////e.printStackTrace(); Assert.Fail(); } Assert.IsNotNull(poifs); /* Read the document summary information. */ dir = poifs.Root; try { DocumentEntry dsiEntry = (DocumentEntry) dir.GetEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(dsiEntry); PropertySet ps = new PropertySet(dis); dis.Close(); dsi = new DocumentSummaryInformation(ps); } catch (FileNotFoundException ex) { Assert.Fail(ex.Message); } catch (IOException e) { //e.printStackTrace(); Assert.Fail(e.Message); } catch (NoPropertySetStreamException e) { //e.printStackTrace(); Assert.Fail(e.Message); } catch (MarkUnsupportedException e) { //e.printStackTrace(); Assert.Fail(e.Message); } catch (UnexpectedPropertySetTypeException e) { //e.printStackTrace(); Assert.Fail(e.Message); } try { DocumentEntry dsiEntry = (DocumentEntry) dir.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(dsiEntry); PropertySet ps = new PropertySet(dis); dis.Close(); si = new SummaryInformation(ps); } catch (FileNotFoundException) { /* There is no document summary information yet. We have to Create a * new one. */ si = PropertySetFactory.CreateSummaryInformation(); Assert.IsNotNull(si); } catch (IOException) { //e.printStackTrace(); Assert.Fail(); } catch (NoPropertySetStreamException) { //e.printStackTrace(); Assert.Fail(); } catch (MarkUnsupportedException) { //e.printStackTrace(); Assert.Fail(); } catch (UnexpectedPropertySetTypeException) { //e.printStackTrace(); Assert.Fail(); } }
/** * 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; }
public void Close() { delegate1.Close(); }