Esempio n. 1
0
        /**
         * Repositions this stream to the position at the time the mark() method was
         * last called on this input stream. If mark() has not been called this
         * method repositions the stream to its beginning.
         */

        public override void Reset()
        {
            // Special case for Reset to the start
            if (_marked_offset == 0 && _marked_offset_count == 0)
            {
                _current_block_count = _marked_offset_count;
                _current_offset      = _marked_offset;
                _data   = _document.GetBlockIterator();
                _buffer = null;
                return;
            }

            // Start again, then wind on to the required block
            _data           = _document.GetBlockIterator();
            _current_offset = 0;

            for (int i = 0; i < _marked_offset_count; i++)
            {
                _data.MoveNext();
                _buffer          = _data.Current;
                _current_offset += _buffer.Remain;
            }

            _current_block_count = _marked_offset_count;

            // Do we need to position within it?
            if (_current_offset != _marked_offset)
            {
                // Grab the right block
                _data.MoveNext();
                _buffer = _data.Current;
                _current_block_count++;

                // Skip to the right place in it
                // (It should be positioned already at the start of the block,
                //  we need to Move further inside the block)
                int skipBy = _marked_offset - _current_offset;
                _buffer.Position = (_buffer.Position + skipBy);
            }

            // All done
            _current_offset = _marked_offset;
        }
Esempio n. 2
0
 /**
  * Create an InputStream from the specified Document
  *
  * @param document the Document to be read
  */
 public NDocumentInputStream(NPOIFSDocument document)
 {
     _current_offset      = 0;
     _current_block_count = 0;
     _marked_offset       = 0;
     _marked_offset_count = 0;
     _document_size       = document.Size;
     _closed   = false;
     _document = document;
     _data     = _document.GetBlockIterator();
 }
Esempio n. 3
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 NDocumentInputStream(DocumentEntry document)
        {
            if (!(document is DocumentNode))
            {
                throw new IOException("Cannot open internal document storage, " + document + " not a Document Node");
            }
            _current_offset      = 0;
            _current_block_count = 0;
            _marked_offset       = 0;
            _marked_offset_count = 0;
            _document_size       = document.Size;
            _closed = false;

            DocumentNode     doc      = (DocumentNode)document;
            DocumentProperty property = (DocumentProperty)doc.Property;

            _document = new NPOIFSDocument(
                property,
                ((DirectoryNode)doc.Parent).NFileSystem
                );
            _data = _document.GetBlockIterator();
        }