public void TestConstructor() { DirectoryProperty property1 = new DirectoryProperty("directory"); RawDataBlock[] rawBlocks = new RawDataBlock[4]; MemoryStream stream = new MemoryStream(new byte[2048]); for (int j = 0; j < 4; j++) { rawBlocks[j] = new RawDataBlock(stream); } POIFSDocument document = new POIFSDocument("document", rawBlocks, 2000); DocumentProperty property2 = document.DocumentProperty; DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem)null, null); DocumentNode node = new DocumentNode(property2, parent); // Verify we can retrieve the document Assert.AreEqual(property2.Document, node.Document); // Verify we can Get the size Assert.AreEqual(property2.Size, node.Size); // Verify isDocumentEntry returns true Assert.IsTrue(node.IsDocumentEntry); // Verify isDirectoryEntry returns false Assert.IsTrue(!node.IsDirectoryEntry); // Verify GetName behaves correctly Assert.AreEqual(property2.Name, node.Name); // Verify GetParent behaves correctly Assert.AreEqual(parent, node.Parent); }
/// <summary> /// Create an InputStream from the specified Document /// </summary> /// <param name="document">the Document to be read</param> public POIFSDocumentReader(POIFSDocument document) { this._current_offset = 0; this._document_size = document.Size; this._closed = false; this._tiny_buffer = null; this._document = document; }
/** * Create an InputStream from the specified Document * * @param document the Document to be read */ public ODocumentInputStream(POIFSDocument document) { _current_offset = 0; _marked_offset = 0; _document_size = document.Size; _closed = false; _document = document; _currentBlock = GetDataInputBlock(0); }
/// <summary> /// Initializes a new instance of the <see cref="DocumentProperty"/> class. /// </summary> /// <param name="name">POIFSDocument name</param> /// <param name="size">POIFSDocument size</param> public DocumentProperty(String name, int size) : base() { _document = null; this.Name=name; this.Size=size; this.NodeColor=_NODE_BLACK; // simplification this.PropertyType=PropertyConstants.DOCUMENT_TYPE; }
/// <summary> /// Create an InputStream from the specified DocumentEntry /// </summary> /// <param name="document">the DocumentEntry to be read</param> public POIFSDocumentReader(DocumentEntry document) { this._current_offset = 0; this._document_size = document.Size; this._closed = false; this._tiny_buffer = null; if (!(document is DocumentNode)) { throw new IOException("Cannot open internal document storage"); } this._document = ((DocumentNode)document).Document; }
/// <summary> /// Create a new DocumentEntry; the data will be provided later /// </summary> /// <param name="document">the name of the new documentEntry</param> /// <returns>the new DocumentEntry</returns> public DocumentEntry CreateDocument(POIFSDocument document) { DocumentProperty property = document.DocumentProperty; DocumentNode rval = new DocumentNode(property, this); ((DirectoryProperty)Property).AddChild(property); _oFilesSystem.AddDocument(document); _entries.Add(rval); _byname.Add(property.Name, rval); return(rval); }
private void ProcessProperties(BlockList small_blocks, BlockList big_blocks, IEnumerator properties, DirectoryNode dir, int headerPropertiesStartAt) { while (properties.MoveNext()) { Property property = ( Property )properties.Current; String name = property.Name; DirectoryNode parent = (dir == null) ? (( DirectoryNode )this.Root) : dir; if (property.IsDirectory) { DirectoryNode new_dir = ( DirectoryNode )parent.CreateDirectory(name); new_dir.StorageClsid = property.StorageClsid; ProcessProperties( small_blocks, big_blocks, ((DirectoryProperty)property).Children, new_dir, headerPropertiesStartAt); } else { int startBlock = property.StartBlock; int size = property.Size; POIFSDocument document = null; if (property.ShouldUseSmallBlocks) { document = new POIFSDocument(name, small_blocks .FetchBlocks(startBlock, headerPropertiesStartAt), size); } else { document = new POIFSDocument(name, big_blocks.FetchBlocks(startBlock, headerPropertiesStartAt), size); } parent.CreateDocument(document); } } }
public TestDocumentInputStream() { int blocks = (_workbook_size + 511) / 512; _workbook_data = new byte[512 * blocks]; Arrays.Fill(_workbook_data, unchecked((byte)-1)); for (int j = 0; j < _workbook_size; j++) { _workbook_data[j] = (byte)(j * j); } // Create the Old POIFS Version RawDataBlock[] rawBlocks = new RawDataBlock[blocks]; MemoryStream stream = new MemoryStream(_workbook_data); for (int j = 0; j < blocks; j++) { rawBlocks[j] = new RawDataBlock(stream); } POIFSDocument document = new POIFSDocument("Workbook", rawBlocks, _workbook_size); _workbook_o = new DocumentNode( document.DocumentProperty, new DirectoryNode( new DirectoryProperty("Root Entry"), (POIFSFileSystem)null, null)); // Now create the NPOIFS Version byte[] _workbook_data_only = new byte[_workbook_size]; Array.Copy(_workbook_data, 0, _workbook_data_only, 0, _workbook_size); NPOIFSFileSystem npoifs = new NPOIFSFileSystem(); // Make it easy when debugging to see what isn't the doc byte[] minus1 = new byte[512]; Arrays.Fill(minus1, unchecked((byte)-1)); npoifs.GetBlockAt(-1).Write(minus1); npoifs.GetBlockAt(0).Write(minus1); npoifs.GetBlockAt(1).Write(minus1); // Create the NPOIFS document _workbook_n = (DocumentNode)npoifs.CreateDocument( new MemoryStream(_workbook_data_only), "Workbook" ); }
/** * 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 ODocumentInputStream(DocumentEntry document) { if (!(document is DocumentNode)) { throw new IOException("Cannot open internal document storage"); } DocumentNode documentNode = (DocumentNode)document; if (documentNode.Document == null) { throw new IOException("Cannot open internal document storage"); } _current_offset = 0; _marked_offset = 0; _document_size = document.Size; _closed = false; _document = documentNode.Document; _currentBlock = GetDataInputBlock(0); }
private POIFSDocument makeCopy(POIFSDocument document, byte[] input, byte[] data) { POIFSDocument copy = null; if (input.Length >= 4096) { RawDataBlock[] blocks = new RawDataBlock[(input.Length + 511) / 512]; MemoryStream stream = new MemoryStream(data); int index = 0; while (true) { RawDataBlock block = new RawDataBlock(stream); if (block.EOF) { break; } blocks[index++] = block; } copy = new POIFSDocument("test" + input.Length, blocks, input.Length); } else { copy = new POIFSDocument( "test" + input.Length, (SmallDocumentBlock[])document.SmallBlocks, input.Length); } return copy; }
/** * create a DocumentNode. This method Is not public by design; it * Is intended strictly for the internal use of this package * * @param property the DocumentProperty for this DocumentEntry * @param parent the parent of this entry */ public DocumentNode(DocumentProperty property, DirectoryNode parent) : base(property, parent) { _document = property.Document; }
/** * create a DocumentNode. This method Is not public by design; it * Is intended strictly for the internal use of this package * * @param property the DocumentProperty for this DocumentEntry * @param parent the parent of this entry */ public DocumentNode(DocumentProperty property, DirectoryNode parent):base(property, parent) { _document = property.Document; }
/// <summary> /// Initializes a new instance of the <see cref="DocumentProperty"/> class. /// </summary> /// <param name="index">index number</param> /// <param name="array">byte data</param> /// <param name="offset">offset into byte data</param> public DocumentProperty(int index, byte [] array, int offset):base(index, array, offset) { _document = null; }
private byte[] checkValues(int big_blocks, int small_blocks, int total_output, POIFSDocument document, byte[] input) { Assert.AreEqual(document, document.DocumentProperty.Document); int increment = (int)Math.Sqrt(input.Length); for (int j = 1; j <= input.Length; j += increment) { byte[] buffer = new byte[j]; int offset = 0; for (int k = 0; k < (input.Length / j); k++) { document.Read(buffer, offset); for (int n = 0; n < buffer.Length; n++) { Assert.AreEqual(input[(k * j) + n], buffer[n] , "checking byte " + (k * j) + n); } offset += j; } } Assert.AreEqual(big_blocks, document.CountBlocks); Assert.AreEqual(small_blocks, document.SmallBlocks.Length); MemoryStream stream = new MemoryStream(); document.WriteBlocks(stream); byte[] output = stream.ToArray(); Assert.AreEqual(total_output, output.Length); int limit = Math.Min(total_output, input.Length); for (int j = 0; j < limit; j++) { Assert.AreEqual(input[j], output[j], "Checking document offset " + j); } for (int j = limit; j < output.Length; j++) { Assert.AreEqual(unchecked((byte)-1), output[j], "Checking document offset " + j); } return output; }
public void TestPOIFSDocument() { // Verify correct number of blocks Get Created for document // that is exact multituple of block size POIFSDocument document; byte[] array = new byte[4096]; for (int j = 0; j < array.Length; j++) { array[j] = (byte)j; } document = new POIFSDocument("foo", new SlowInputStream(new MemoryStream(array))); checkDocument(document, array); // Verify correct number of blocks Get Created for document // that is not an exact multiple of block size array = new byte[4097]; for (int j = 0; j < array.Length; j++) { array[j] = (byte)j; } document = new POIFSDocument("bar", new MemoryStream(array)); checkDocument(document, array); // Verify correct number of blocks Get Created for document // that is small array = new byte[4095]; for (int j = 0; j < array.Length; j++) { array[j] = (byte)j; } document = new POIFSDocument("_bar", new MemoryStream(array)); checkDocument(document, array); // Verify correct number of blocks Get Created for document // that is rather small array = new byte[199]; for (int j = 0; j < array.Length; j++) { array[j] = (byte)j; } document = new POIFSDocument("_bar2", new MemoryStream(array)); checkDocument(document, array); // Verify that output is correct array = new byte[4097]; for (int j = 0; j < array.Length; j++) { array[j] = (byte)j; } document = new POIFSDocument("foobar", new MemoryStream(array)); checkDocument(document, array); document.StartBlock=0x12345678; // what a big file!! DocumentProperty property = document.DocumentProperty; MemoryStream stream = new MemoryStream(); property.WriteData(stream); byte[] output = stream.ToArray(); byte[] array2 = { ( byte ) 'f', ( byte ) 0, ( byte ) 'o', ( byte ) 0, ( byte ) 'o', ( byte ) 0, ( byte ) 'b', ( byte ) 0, ( byte ) 'a', ( byte ) 0, ( byte ) 'r', ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 14, ( byte ) 0, ( byte ) 2, ( byte ) 1, unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), unchecked(( byte ) -1), ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0x78, ( byte ) 0x56, ( byte ) 0x34, ( byte ) 0x12, ( byte ) 1, ( byte ) 16, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0, ( byte ) 0 }; Assert.AreEqual(array2.Length, output.Length); for (int j = 0; j < output.Length; j++) { Assert.AreEqual(array2[j], output[j], "Checking property offset " + j); } }
private void ProcessProperties(BlockList small_blocks, BlockList big_blocks, IEnumerator properties, DirectoryNode dir, int headerPropertiesStartAt) { while (properties.MoveNext()) { Property property = ( Property ) properties.Current; String name = property.Name; DirectoryNode parent = (dir == null) ? (( DirectoryNode ) this.Root) : dir; if (property.IsDirectory) { DirectoryNode new_dir = ( DirectoryNode ) parent.CreateDirectory(name); new_dir.StorageClsid=property.StorageClsid ; ProcessProperties( small_blocks, big_blocks, ((DirectoryProperty)property).Children, new_dir, headerPropertiesStartAt); } else { int startBlock = property.StartBlock; int size = property.Size; POIFSDocument document = null; if (property.ShouldUseSmallBlocks) { document = new POIFSDocument(name, small_blocks .FetchBlocks(startBlock, headerPropertiesStartAt), size); } else { document = new POIFSDocument(name, big_blocks.FetchBlocks(startBlock,headerPropertiesStartAt), size); } parent.CreateDocument(document); } } }
// <summary> // open a document in the root entry's list of entries // </summary> // <param name="documentName">the name of the document to be opened</param> // <returns>a newly opened POIFSDocumentReader</returns> //public DocumentReader CreatePOIFSDocumentReader( // String documentName) //{ // return this.Root.CreatePOIFSDocumentReader(documentName); //} /// <summary> /// Add a new POIFSDocument /// </summary> /// <param name="document">the POIFSDocument being Added</param> public void AddDocument(POIFSDocument document) { _documents.Add(document); _property_table.AddProperty(document.DocumentProperty); }
/** * Create an InputStream from the specified Document * * @param document the Document to be read */ public DocumentInputStream(POIFSDocument document) { delegate1 = new ODocumentInputStream(document); }
private void checkDocument(POIFSDocument document, byte[] input) { int big_blocks = 0; int small_blocks = 0; int total_output = 0; if (input.Length >= 4096) { big_blocks = (input.Length + 511) / 512; total_output = big_blocks * 512; } else { small_blocks = (input.Length + 63) / 64; total_output = 0; } checkValues( big_blocks, small_blocks, total_output, makeCopy( document, input, checkValues( big_blocks, small_blocks, total_output, document, input)), input); }
public POIFSReaderEventArgs(string name, POIFSDocumentPath path, POIFSDocument document) { this.name = name; this.path = path; this.document = document; }
/// <summary> /// Processes the properties. /// </summary> /// <param name="small_blocks">The small_blocks.</param> /// <param name="big_blocks">The big_blocks.</param> /// <param name="properties">The properties.</param> /// <param name="path">The path.</param> /// <returns></returns> private List<DocumentDescriptor> ProcessProperties(BlockList small_blocks, BlockList big_blocks, IEnumerator properties, POIFSDocumentPath path) { List<DocumentDescriptor> documents = new List<DocumentDescriptor>(); while (properties.MoveNext()) { Property property = (Property)properties.Current; String name = property.Name; if (property.IsDirectory) { POIFSDocumentPath new_path = new POIFSDocumentPath(path, new String[] { name }); ProcessProperties( small_blocks, big_blocks, ((DirectoryProperty)property).Children, new_path); } else { int startBlock = property.StartBlock; IEnumerator listeners = registry.GetListeners(path, name); POIFSDocument document = null; if (listeners.MoveNext()) { listeners.Reset(); int size = property.Size; if (property.ShouldUseSmallBlocks) { document = new POIFSDocument(name, small_blocks .FetchBlocks(startBlock, -1), size); } else { document = new POIFSDocument(name, big_blocks .FetchBlocks(startBlock, -1), size); } //POIFSReaderListener listener = // (POIFSReaderListener)listeners.Current; //listener.ProcessPOIFSReaderEvent( // new POIFSReaderEvent( // new DocumentInputStream(document), path, // name)); while (listeners.MoveNext()) { POIFSReaderListener listener = (POIFSReaderListener)listeners.Current; listener.ProcessPOIFSReaderEvent( new POIFSReaderEvent( new DocumentInputStream(document), path, name)); } } else { // consume the document's data and discard it if (property.ShouldUseSmallBlocks) { small_blocks.FetchBlocks(startBlock, -1); } else { big_blocks.FetchBlocks(startBlock, -1); } //documents.Add( // new DocumentDescriptor(path, name)); //fire event //OnStreamReaded(new POIFSReaderEventArgs(name, path, document)); } } } return documents; }