コード例 #1
0
ファイル: NPOIFSDocument.cs プロジェクト: shnug/OLE2Storage
        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());
        }
コード例 #2
0
ファイル: NPOIFSDocument.cs プロジェクト: shnug/OLE2Storage
        /**
         * Constructor for an existing Document
         */
        public NPOIFSDocument(DocumentProperty property, NPOIFSFileSystem filesystem)
        {
            this._property   = property;
            this._filesystem = filesystem;

            if (property.Size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE)
            {
                _stream     = new NPOIFSStream(_filesystem.GetMiniStore(), property.StartBlock);
                _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize();
            }
            else
            {
                _stream     = new NPOIFSStream(_filesystem, property.StartBlock);
                _block_size = _filesystem.GetBlockStoreBlockSize();
            }
        }
コード例 #3
0
ファイル: NPOIFSDocument.cs プロジェクト: newlysoft/NStorage
        /**
         * Constructor for an existing Document 
         */
        public NPOIFSDocument(DocumentProperty property, NPOIFSFileSystem filesystem)
        {
            this._property = property;
            this._filesystem = filesystem;

            if (property.Size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE)
            {
                _stream = new NPOIFSStream(_filesystem.GetMiniStore(), property.StartBlock);
                _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize();
            }
            else
            {
                _stream = new NPOIFSStream(_filesystem, property.StartBlock);
                _block_size = _filesystem.GetBlockStoreBlockSize();
            }
        }
コード例 #4
0
ファイル: NPOIFSDocument.cs プロジェクト: shnug/OLE2Storage
        private int Store(Stream inStream)
        {
            int bigBlockSize = POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE;

            //BufferedStream bis = new BufferedStream(stream, bigBlockSize + 1);
            //bis.mark(bigBlockSize);

            //// Buffer the contents into memory. This is a bit icky...
            //// TODO Replace with a buffer up to the mini stream size, then streaming write
            //byte[] contents;
            //if (stream is MemoryStream)
            //{
            //    MemoryStream bais = (MemoryStream)stream;
            //    contents = new byte[bais.Length];
            //    bais.Read(contents, 0, contents.Length);
            //}
            //else
            //{
            //    MemoryStream baos = new MemoryStream();
            //    IOUtils.Copy(stream, baos);
            //    contents = baos.ToArray();
            //}

            // Do we need to store as a mini stream or a full one?
            if (inStream.Length < bigBlockSize)
            {
                _stream     = new NPOIFSStream(_filesystem.GetMiniStore());
                _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize();
            }
            else
            {
                _stream     = new NPOIFSStream(_filesystem);
                _block_size = _filesystem.GetBlockStoreBlockSize();
            }

            // start from the beginning
            //bis.Seek(0, SeekOrigin.Begin);

            // Store it
            Stream outStream = _stream.GetOutputStream();

            byte[] buf    = new byte[1024];
            int    length = 0;

            //for (int readBytes; (readBytes = bis.Read(buf, 0, buf.Length)) != 0; length += readBytes)
            //{
            //    outStream.Write(buf, 0, readBytes);
            //}

            for (int readBytes = 0; ;)
            {
                readBytes = inStream.Read(buf, 0, buf.Length);
                if (readBytes <= 0)
                {
                    break;
                }
                length += readBytes;
                outStream.Write(buf, 0, readBytes);
            }
            outStream.Close();
            return(length);
        }
コード例 #5
0
ファイル: NPOIFSDocument.cs プロジェクト: newlysoft/NStorage
        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());
        }