Ejemplo n.º 1
0
        /// <summary>
        /// Set BAT block parameters. Assumes that all BAT blocks are
        /// contiguous. Will construct XBAT blocks if necessary and return
        /// the array of newly constructed XBAT blocks.
        /// </summary>
        /// <param name="blockCount">count of BAT blocks</param>
        /// <param name="startBlock">index of first BAT block</param>
        /// <returns>array of XBAT blocks; may be zero Length, will not be
        /// null</returns>
        public BATBlock [] SetBATBlocks(int blockCount,
                                        int startBlock)
        {
            BATBlock[] rvalue;

            _bat_count.Set(blockCount, _data);
            int limit  = Math.Min(blockCount, HeaderBlockConstants._max_bats_in_header);
            int offset = HeaderBlockConstants._bat_array_offset;

            for (int j = 0; j < limit; j++)
            {
                new IntegerField(offset, startBlock + j, _data);
                offset += LittleEndianConstants.INT_SIZE;
            }
            if (blockCount > HeaderBlockConstants._max_bats_in_header)
            {
                int   excess_blocks      = blockCount - HeaderBlockConstants._max_bats_in_header;
                int[] excess_block_array = new int[excess_blocks];

                for (int j = 0; j < excess_blocks; j++)
                {
                    excess_block_array[j] = startBlock + j
                                            + HeaderBlockConstants._max_bats_in_header;
                }
                rvalue = BATBlock.CreateXBATBlocks(excess_block_array,
                                                   startBlock + blockCount);
                _xbat_start.Set(startBlock + blockCount, _data);
            }
            else
            {
                rvalue = BATBlock.CreateXBATBlocks(new int[0], 0);
                _xbat_start.Set(POIFSConstants.END_OF_CHAIN, _data);
            }
            _xbat_count.Set(rvalue.Length, _data);
            return(rvalue);
        }
Ejemplo n.º 2
0
        public void TestSet()
        {
            IntegerField field = new IntegerField(0);

            byte[] array = new byte[4];

            for (int j = 0; j < _test_array.Length; j++)
            {
                field.Value = _test_array[j];
                Assert.AreEqual(_test_array[j], field.Value, "testing _1 " + j);
                field = new IntegerField(0);
                field.Set(_test_array[j], array);
                Assert.AreEqual(_test_array[j], field.Value, "testing _2 ");
                Assert.AreEqual((byte)(_test_array[j] % 256), array[0], "testing _3.0 " + _test_array[j]);
                Assert.AreEqual(( byte )((_test_array[j] >> 8) % 256),
                                array[1], "testing _3.1 " + _test_array[j]);
                Assert.AreEqual(( byte )((_test_array[j] >> 16) % 256),
                                array[2], "testing _3.2 " + _test_array[j]);
                Assert.AreEqual(( byte )((_test_array[j] >> 24) % 256),
                                array[3], "testing _3.3 " + _test_array[j]);
            }
        }