public override long ReadLong() { CheckAvaliable(SIZE_LONG); int blockAvailable = _currentBlock.Available(); long result; if (blockAvailable > SIZE_LONG) { result = _currentBlock.ReadLongLE(); } else { DataInputBlock nextBlock = GetDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_LONG) { result = _currentBlock.ReadLongLE(); } else { result = nextBlock.ReadLongLE(_currentBlock, blockAvailable); } _currentBlock = nextBlock; } _current_offset += SIZE_LONG; return(result); }
public override int ReadUShort() { CheckAvaliable(SIZE_SHORT); int blockAvailable = _currentBlock.Available(); int result; if (blockAvailable > SIZE_SHORT) { result = _currentBlock.ReadUshortLE(); } else { DataInputBlock nextBlock = GetDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_SHORT) { result = _currentBlock.ReadUshortLE(); } else { result = nextBlock.ReadUshortLE(_currentBlock); } _currentBlock = nextBlock; } _current_offset += SIZE_SHORT; return(result); }
/// <summary> /// read data from the internal stores /// </summary> /// <param name="buffer">the buffer to write to</param> /// <param name="offset">the offset into our storage to read from</param> public virtual void Read(byte[] buffer, int offset) { //if (this._property.ShouldUseSmallBlocks) //{ // SmallDocumentBlock.Read(this._small_store.Blocks, buffer, offset); //} //else //{ // DocumentBlock.Read(this._big_store.Blocks, buffer, offset); //} int len = buffer.Length; DataInputBlock currentBlock = GetDataInputBlock(offset); int blockAvailable = currentBlock.Available(); if (blockAvailable > len) { currentBlock.ReadFully(buffer, 0, len); return; } // else read big amount in chunks int remaining = len; int writePos = 0; int currentOffset = offset; while (remaining > 0) { bool blockIsExpiring = remaining >= blockAvailable; int reqSize; if (blockIsExpiring) { reqSize = blockAvailable; } else { reqSize = remaining; } currentBlock.ReadFully(buffer, writePos, reqSize); remaining -= reqSize; writePos += reqSize; currentOffset += reqSize; if (blockIsExpiring) { if (currentOffset == _size) { if (remaining > 0) { throw new InvalidOperationException("reached end of document stream unexpectedly"); } currentBlock = null; break; } currentBlock = GetDataInputBlock(currentOffset); blockAvailable = currentBlock.Available(); } } }
/** * 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); }
public override int ReadUByte() { CheckAvaliable(1); int result = _currentBlock.ReadUByte(); _current_offset++; if (_currentBlock.Available() < 1) { _currentBlock = GetDataInputBlock(_current_offset); } return(result); }
public override void ReadFully(byte[] buf, int off, int len) { CheckAvaliable(len); int blockAvailable = _currentBlock.Available(); if (blockAvailable > len) { _currentBlock.ReadFully(buf, off, len); _current_offset += len; return; } // else read big amount in chunks int remaining = len; int WritePos = off; while (remaining > 0) { bool blockIsExpiring = remaining >= blockAvailable; int reqSize; if (blockIsExpiring) { reqSize = blockAvailable; } else { reqSize = remaining; } _currentBlock.ReadFully(buf, WritePos, reqSize); remaining -= reqSize; WritePos += reqSize; _current_offset += reqSize; if (blockIsExpiring) { if (_current_offset == _document_size) { if (remaining > 0) { throw new InvalidOperationException( "reached end of document stream unexpectedly"); } _currentBlock = null; break; } _currentBlock = GetDataInputBlock(_current_offset); blockAvailable = _currentBlock.Available(); } } }
public override int Read() { dieIfClosed(); if (atEOD()) { return(EOF); } int result = _currentBlock.ReadUByte(); _current_offset++; if (_currentBlock.Available() < 1) { _currentBlock = GetDataInputBlock(_current_offset); } return(result); }
/** * 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); }
public override long Skip(long n) { dieIfClosed(); if (n < 0) { return(0); } long new_offset = _current_offset + (int)n; if (new_offset < _current_offset) { // wrap around in Converting a VERY large long to an int new_offset = _document_size; } else if (new_offset > _document_size) { new_offset = _document_size; } long rval = new_offset - _current_offset; _current_offset = new_offset; _currentBlock = GetDataInputBlock(_current_offset); return(rval); }
/** * 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() { _current_offset = _marked_offset; _currentBlock = GetDataInputBlock(_current_offset); }