예제 #1
0
 public void Dispose()
 {
     bigBlocks         = null;
     enclosingInstance = null;
     name = null;
     path = null;
 }
예제 #2
0
        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);
        }
예제 #3
0
 public void Dispose()
 {
     enclosingInstance = null;
     path        = null;
     smallBlocks = null;
     name        = null;
 }
예제 #4
0
 /// <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;
 }
예제 #5
0
        /// <summary>
        /// Create a new DocumentEntry; the data will be provided later
        /// </summary>
        /// <param name="name">the name of the new DocumentEntry</param>
        /// <param name="size">the size of the new DocumentEntry</param>
        /// <param name="beforewriting"></param>
        /// <returns>the new DocumentEntry</returns>
        public DocumentEntry CreateDocument(String name, int size,
                                            POIFSWriterEventHandler beforewriting)
        {
            POIFSDocument document = new POIFSDocument(name, size, _path);

            document.BeforeWriting += beforewriting;
            return(CreateDocument(document));
        }
예제 #6
0
 internal SmallBlockStore(POIFSDocument enclosingInstance, POIFSDocumentPath path, string name, int size)
 {
     this.InitBlock(enclosingInstance);
     this.smallBlocks = new SmallDocumentBlock[0];
     this.path        = path;
     this.name        = name;
     this.size        = size;
 }
예제 #7
0
 /// <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;
 }
예제 #8
0
 /**
  * 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);
 }
예제 #9
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)
        {
            _document = null;

            this.Name=name;
            this.Size=size;
            this.NodeColor=_NODE_BLACK;   // simplification
            this.PropertyType=PropertyConstants.DOCUMENT_TYPE;
        }
예제 #10
0
        /// <summary>
        /// Create a new DocumentEntry
        /// </summary>
        /// <param name="document">the new document</param>
        /// <returns>the new DocumentEntry</returns>
        internal DocumentEntry CreateDocument(POIFSDocument document)
        {
            DocumentProperty property = document.DocumentProperty;
            DocumentNode     rval     = new DocumentNode(property, this);

            (( DirectoryProperty )Property).AddChild(property);
            _filesystem.AddDocument(document);
            _entries[property.Name] = rval;
            return(rval);
        }
예제 #11
0
 internal SmallBlockStore(POIFSDocument enclosingInstance, object[] blocks)
 {
     this.InitBlock(enclosingInstance);
     this.smallBlocks = new SmallDocumentBlock[blocks.Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         this.smallBlocks[i] = (SmallDocumentBlock)blocks[i];
     }
     this.path = null;
     this.name = null;
     this.size = -1;
 }
예제 #12
0
 /// <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;
 }
예제 #13
0
 /// <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;
 }
예제 #14
0
        /// <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);
        }
예제 #15
0
 public void Dispose()
 {
     if (_documents != null)
     {
         for (int i = 0; i < _documents.Count; i++)
         {
             POIFSDocument doc = (POIFSDocument)_documents[i];
             if (doc != null)
             {
                 doc.Dispose();
             }
         }
     }
 }
예제 #16
0
        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);
                }
            }
        }
예제 #17
0
        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"
            );
        }
예제 #18
0
 internal BigBlockStore(POIFSDocument enclosingInstance, object[] blocks)
 {
     this.InitBlock(enclosingInstance);
     this.bigBlocks = new DocumentBlock[blocks.Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         if (blocks[i] is DocumentBlock)
         {
             this.bigBlocks[i] = (DocumentBlock)blocks[i];
         }
         else
         {
             this.bigBlocks[i] = new DocumentBlock((RawDataBlock)blocks[i]);
         }
     }
     this.path = null;
     this.name = null;
     this.size = -1;
 }
예제 #19
0
        /**
         * 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);
        }
예제 #20
0
        /**
         * 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);
        }
예제 #21
0
 /**
  * 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);
 }
예제 #22
0
 /**
  * Create an InputStream from the specified Document
  * 
  * @param document the Document to be read
  */
 public DocumentInputStream(POIFSDocument document)
 {
     delegate1 = new ODocumentInputStream(document);
 }
예제 #23
0
 public POIFSReaderEventArgs(string name, POIFSDocumentPath path, POIFSDocument document)
 {
     this.name = name;
     this.path = path;
     this.document = document;
 }
예제 #24
0
        // <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);
        }
예제 #25
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;
        }
예제 #26
0
 /**
  * Create an InputStream from the specified Document
  *
  * @param document the Document to be read
  */
 public DocumentInputStream(POIFSDocument document)
 {
     delegate1 = new ODocumentInputStream(document);
 }
예제 #27
0
        // <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);
        }
예제 #28
0
 internal SmallBlockStore(POIFSDocument enclosingInstance, object[] blocks)
 {
     this.InitBlock(enclosingInstance);
     this.smallBlocks = new SmallDocumentBlock[blocks.Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         this.smallBlocks[i] = (SmallDocumentBlock)blocks[i];
     }
     this.path = null;
     this.name = null;
     this.size = -1;
 }
예제 #29
0
        /// <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;
        }
예제 #30
0
        /// <summary>
        /// Create a new DocumentEntry
        /// </summary>
        /// <param name="document">the new document</param>
        /// <returns>the new DocumentEntry</returns>
        internal DocumentEntry CreateDocument(POIFSDocument document)
        {
            DocumentProperty property = document.DocumentProperty;
            DocumentNode     rval     = new DocumentNode(property, this);

            (( DirectoryProperty ) Property).AddChild(property);
            _filesystem.AddDocument(document);
            _entries[property.Name]=rval;
            return rval;
        }
예제 #31
0
 /// <summary>
 /// Create a new DocumentEntry; the data will be provided later
 /// </summary>
 /// <param name="name">the name of the new DocumentEntry</param>
 /// <param name="size">the size of the new DocumentEntry</param>
 /// <param name="beforewriting"></param>
 /// <returns>the new DocumentEntry</returns>
 public DocumentEntry CreateDocument(String name, int size,
                                     POIFSWriterEventHandler beforewriting)
 {
     POIFSDocument document = new POIFSDocument(name, size, _path);
     document.BeforeWriting += beforewriting;
     return CreateDocument(document);
 }
예제 #32
0
 internal SmallBlockStore(POIFSDocument enclosingInstance, POIFSDocumentPath path, string name, int size)
 {
     this.InitBlock(enclosingInstance);
     this.smallBlocks = new SmallDocumentBlock[0];
     this.path = path;
     this.name = name;
     this.size = size;
 }
예제 #33
0
 public void Dispose()
 {
     enclosingInstance = null;
     path = null;
     smallBlocks = null;
     name = null;
 }
예제 #34
0
        /**
         * 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;
        }
예제 #35
0
 private void InitBlock(POIFSDocument enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
예제 #36
0
 public void Dispose()
 {
     _document = null;
 }
예제 #37
0
 public override void Dispose()
 {
     _document = null;
 }
예제 #38
0
 /**
  * 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;
 }
예제 #39
0
        /// <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;


                    int size = property.Size;
                    POIFSDocument document = null;

                    if (property.ShouldUseSmallBlocks)
                    {
                        document =
                            new POIFSDocument(name, small_blocks
                                .FetchBlocks(startBlock,-1), size);
                    }
                    else
                    {
                        document =
                            new POIFSDocument(name, big_blocks
                                .FetchBlocks(startBlock,-1), size);
                    }

                    documents.Add(
                            new DocumentDescriptor(path, name));
                    //fire event
                    OnStreamReaded(new POIFSReaderEventArgs(name, path, document));
                }
            }
            return documents;
        }
예제 #40
0
 public void Dispose()
 {
     bigBlocks = null;
     enclosingInstance = null;
     name = null;
     path = null;
 }
예제 #41
0
        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);
                }
            }
        }
예제 #42
0
 internal BigBlockStore(POIFSDocument enclosingInstance, object[] blocks)
 {
     this.InitBlock(enclosingInstance);
     this.bigBlocks = new DocumentBlock[blocks.Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         if (blocks[i] is DocumentBlock)
         {
             this.bigBlocks[i] = (DocumentBlock)blocks[i];
         }
         else
         {
             this.bigBlocks[i] = new DocumentBlock((RawDataBlock)blocks[i]);
         }
     }
     this.path = null;
     this.name = null;
     this.size = -1;
 }
예제 #43
0
        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);
        }
예제 #44
0
 private void InitBlock(POIFSDocument enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
예제 #45
0
        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;
        }
예제 #46
0
        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);
            }
        }
예제 #47
0
 /// <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;
 }
예제 #48
0
 public void Dispose()
 {
     _document = null;
 }