public NPOIFSDocument(String name, int size, NPOIFSFileSystem filesystem, POIFSWriterListener Writer) { this._filesystem = filesystem; if (size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { _stream = new NPOIFSStream(filesystem.GetMiniStore()); _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize(); } else { _stream = new NPOIFSStream(filesystem); _block_size = _filesystem.GetBlockStoreBlockSize(); } Stream innerOs = _stream.GetOutputStream(); DocumentOutputStream os = new DocumentOutputStream(innerOs, size); POIFSDocumentPath path = new POIFSDocumentPath(name.Split(new string[] { "\\\\" }, StringSplitOptions.RemoveEmptyEntries)); String docName = path.GetComponent(path.Length - 1); POIFSWriterEvent event1 = new POIFSWriterEvent(os, path, docName, size); Writer.ProcessPOIFSWriterEvent(event1); innerOs.Close(); // And build the property for it this._property = new DocumentProperty(name, size); _property.StartBlock = (/*setter*/ _stream.GetStartBlock()); }
/// <summary> /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>. /// </summary> /// <returns> /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>. /// </returns> public override String ToString() { StringBuilder buffer = new StringBuilder(40 * (path.Length + 1)); for (int j = 0; j < path.Length; j++) { buffer.Append(path.GetComponent(j)).Append("/"); } buffer.Append(name); return(buffer.ToString()); }
public void TestFullPathConstructor() { string[] components = { "foo", "bar", "foobar", "fubar" }; for (int j = 0; j < components.Length; j++) { string[] pms = new string[j]; for (int k = 0; k < j; k++) { pms[k] = components[k]; } POIFSDocumentPath path = new POIFSDocumentPath(pms); Assert.AreEqual(j, path.Length); for (int k = 0; k < j; k++) { Assert.AreEqual(components[k], path.GetComponent(k)); } if (j == 0) Assert.IsNull(path.Parent); else { POIFSDocumentPath parent = path.Parent; Assert.IsNotNull(parent); Assert.AreEqual(j - 1, parent.Length); for (int k = 0; k < j - 1; k++) Assert.AreEqual(components[k], parent.GetComponent(k)); } } // Test weird variants Assert.AreEqual(0, new POIFSDocumentPath(null).Length); try { new POIFSDocumentPath(new string[] { "fu", "" }); Assert.Fail("Should have caught IllegalArgumentException"); } catch (ArgumentException) { } try { new POIFSDocumentPath(new string[] { "fu", null }); Assert.Fail("Should have caught IllegalArgumentException"); } catch (ArgumentException) { } }
public void TestRelativePathConstructor() { string[] initialComponents = { "a", "b", "c" }; for (int n = 0; n < initialComponents.Length; n++) { String[] initialParams = new String[n]; for (int k = 0; k < n; k++) initialParams[k] = initialComponents[k]; POIFSDocumentPath b = new POIFSDocumentPath(initialParams); string[] components = { "foo", "bar", "foobar", "fubar" }; for (int j = 0; j < components.Length; j++) { String[] params1 = new String[j]; for (int k = 0; k < j; k++) { params1[k] = components[k]; } POIFSDocumentPath path = new POIFSDocumentPath(b, params1); Assert.AreEqual(j + n, path.Length); for (int k = 0; k < n; k++) { Assert.AreEqual(initialComponents[k], path.GetComponent(k)); } for (int k = 0; k < j; k++) { Assert.AreEqual(components[k], path.GetComponent(k + n)); } if ((j + n) == 0) { Assert.IsNull(path.Parent); } else { POIFSDocumentPath parent = path.Parent; Assert.IsNotNull(parent); Assert.AreEqual(j + n - 1, parent.Length); for (int k = 0; k < (j + n - 1); k++) { Assert.AreEqual(path.GetComponent(k), parent.GetComponent(k)); } } } Assert.AreEqual(n, new POIFSDocumentPath(b, null).Length); //this one is allowed. new POIFSDocumentPath(b, new string[] { "fu", "" }); //this one is allowed too new POIFSDocumentPath(b, new string[] { "", "fu" }); //this one is not allowed. try { new POIFSDocumentPath(b, new string[] { "fu", null }); Assert.Fail("should have caught ArgumentException"); } catch (ArgumentException) { } try { new POIFSDocumentPath(b, new string[] { "fu", null }); Assert.Fail("should have caught ArgumentException"); } catch (ArgumentException) { } } }
public NPOIFSDocument(String name, int size, NPOIFSFileSystem filesystem, POIFSWriterListener Writer) { this._filesystem = filesystem; if (size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { _stream = new NPOIFSStream(filesystem.GetMiniStore()); _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize(); } else { _stream = new NPOIFSStream(filesystem); _block_size = _filesystem.GetBlockStoreBlockSize(); } Stream innerOs = _stream.GetOutputStream(); DocumentOutputStream os = new DocumentOutputStream(innerOs, size); POIFSDocumentPath path = new POIFSDocumentPath(name.Split(new string[] { "\\\\" }, StringSplitOptions.RemoveEmptyEntries)); String docName = path.GetComponent(path.Length - 1); POIFSWriterEvent event1 = new POIFSWriterEvent(os, path, docName, size); Writer.ProcessPOIFSWriterEvent(event1); innerOs.Close(); // And build the property for it this._property = new DocumentProperty(name, size); _property.StartBlock = (/*setter*/_stream.GetStartBlock()); }