Ejemplo n.º 1
0
        /// <summary>read block data</summary>
        /// <exception cref="Com.Khubla.Pdxreader.Api.PDXReaderException"/>
        private void ReadBlocks(BufferedInputStream bufferedInputStream, PDXReaderListener
                                pdxReaderListener)
        {
            try
            {
                /*
                 * init the array
                 */
                blocks = new Hashtable <int, DBTableBlock>();

                /*
                 * skip to the first block
                 */
                int nSkip = dbTableHeader.GetBlockSize().GetValue() * 1024;
                if (nSkip == bufferedInputStream.Skip(nSkip))
                {
                    /*
                     * walk blocks
                     */
                    int blocksInUse = dbTableHeader.GetBlocksInUse();
                    for (int i = 0; i < blocksInUse; i++)
                    {
                        /*
                         * block
                         */
                        DBTableBlock pdxTableBlock = new DBTableBlock(i + 1, dbTableHeader.CalculateRecordsPerBlock
                                                                          (), dbTableHeader.GetFields());

                        /*
                         * mark at the start of the block
                         */
                        bufferedInputStream.Mark(MaxBlockSize);

                        /*
                         * read the block data
                         */
                        pdxTableBlock.Read(pdxReaderListener, bufferedInputStream);

                        /*
                         * store it. blocks are numbered from 1, not from 0.
                         */
                        blocks[pdxTableBlock.GetBlockNumber()] = pdxTableBlock;

                        /*
                         * reset to the start of the block
                         */
                        bufferedInputStream.Reset();

                        /*
                         * skip ahead to next block
                         */
                        bufferedInputStream.Skip(dbTableHeader.GetBlockSize().GetValue() * 1024);
                    }
                }
                else
                {
                    throw new PDXReaderException("File format exception");
                }
            }
            catch (Exception e)
            {
                throw new PDXReaderException("Exception in readBlocks", e);
            }
        }
Ejemplo n.º 2
0
        /// <summary>read block data</summary>
        /// <exception cref="Com.Khubla.Pdxreader.Api.PDXReaderException"/>
        private void ReadBlocks(BufferedInputStream bufferedInputStream)
        {
            try
            {
                /*
                 * init the array
                 */
                blocks = new List <PXIndexBlock>();

                /*
                 * skip to the first index block
                 */
                int nSkip = pxFileHeader.GetBlockSize().GetValue() * 1024;
                if (nSkip == bufferedInputStream.Skip(nSkip))
                {
                    /*
                     * walk index blocks
                     */
                    int blocksInUse = pxFileHeader.GetBlocksInUse();
                    for (int i = 0; i < blocksInUse; i++)
                    {
                        /*
                         * block
                         */
                        PXIndexBlock pxIndexBlock = new PXIndexBlock();

                        /*
                         * mark at the start of the block
                         */
                        bufferedInputStream.Mark(MaxBlockSize);

                        /*
                         * read the block data
                         */
                        pxIndexBlock.Read(bufferedInputStream);

                        /*
                         * store it. blocks are numbered from 1, not from 0.
                         */
                        blocks.Add(pxIndexBlock);

                        /*
                         * reset to the start of the block
                         */
                        bufferedInputStream.Reset();

                        /*
                         * skip ahead to next block
                         */
                        bufferedInputStream.Skip(pxFileHeader.GetBlockSize().GetValue() * 1024);
                    }
                }
                else
                {
                    throw new PDXReaderException("File format exception");
                }
            }
            catch (Exception e)
            {
                throw new PDXReaderException("Exception in readBlocks", e);
            }
        }