Example #1
0
        /**
         * Load the block at the given offset.
         */
        public override ByteBuffer GetBlockAt(int offset)
        {
            // Which big block is this?
            int byteOffset     = offset * POIFSConstants.SMALL_BLOCK_SIZE;
            int bigBlockNumber = byteOffset / _filesystem.GetBigBlockSize();
            int bigBlockOffset = byteOffset % _filesystem.GetBigBlockSize();

            // Now locate the data block for it
            StreamBlockByteBufferIterator it = _mini_stream.GetBlockIterator() as StreamBlockByteBufferIterator;

            for (int i = 0; i < bigBlockNumber; i++)
            {
                it.Next();
            }
            ByteBuffer dataBlock = it.Next();

            if (dataBlock == null)
            {
                throw new IndexOutOfRangeException("Big block " + bigBlockNumber + " outside stream");
            }

            // Position ourselves, and take a slice
            dataBlock.Position = dataBlock.Position + bigBlockOffset;
            ByteBuffer miniBuffer = dataBlock.Slice();

            miniBuffer.Limit = POIFSConstants.SMALL_BLOCK_SIZE;
            return(miniBuffer);
        }
Example #2
0
 public IEnumerator <ByteBuffer> GetBlockIterator()
 {
     if (Size > 0)
     {
         return(_stream.GetBlockIterator());
     }
     else
     {
         //List<byte[]> empty = Collections.emptyList();
         List <ByteBuffer> empty = new List <ByteBuffer>();
         return(empty.GetEnumerator());
     }
 }