/**
         * Constructor
         *
         * @param file the file
         * @param propertySet the property set to read
         * @param os the output stream
         * @exception IOException
         * @exception BiffException
         */
        public PropertySetsReader(FileInfo file, string propertySet, TextWriter os)
        {
            //writer = new BufferedWriter(new OutputStreamWriter(os));
            Stream fis = new FileStream(file.Name,FileMode.Open,FileAccess.Read);

            int initialFileSize = 1024 * 1024; // 1mb
            int arrayGrowSize = 1024 * 1024;// 1mb

            byte[] d = new byte[initialFileSize];
            int bytesRead = fis.Read(d,0,d.Length);
            int pos = bytesRead;

            while (bytesRead != -1)
                {
                if (pos >= d.Length)
                    {
                    // Grow the array
                    byte[] newArray = new byte[d.Length + arrayGrowSize];
                    Array.Copy(d, 0, newArray, 0, d.Length);
                    d = newArray;
                    }
                bytesRead = fis.Read(d, pos, d.Length - pos);
                pos += bytesRead;
                }

            bytesRead = pos + 1;

            compoundFile = new CompoundFile(d, new WorkbookSettings());
            fis.Close();

            if (propertySet == null)
                displaySets(os);
            else
                displayPropertySet(propertySet, os);
        }
예제 #2
0
        /**
         * Constructs a file from the input stream
         *
         * @param is the input stream
         * @param ws the workbook settings
         * @exception IOException
         * @exception BiffException
         */
        public File(Stream input, WorkbookSettings ws)
        {
            // Initialize the file sizing parameters from the settings
            workbookSettings = ws;
            initialFileSize  = workbookSettings.getInitialFileSize();
            arrayGrowSize    = workbookSettings.getArrayGrowSize();

            byte[] d         = new byte[initialFileSize];
            int    bytesRead = input.Read(d, 0, d.Length);
            int    pos       = bytesRead;

            // Handle thread interruptions, in case the user keeps pressing
            // the Submit button from a browser.  Thanks to Mike Smith for this
// TODO: CML - don't know what to do with this in context of asp.net
            //if (Thread.currentThread().isInterrupted())
            //    {
            //    throw new InterruptedIOException();
            //    }

            while (bytesRead > 0)
            {
                if (pos >= d.Length)
                {
                    // Grow the array
                    byte[] newArray = new byte[d.Length + arrayGrowSize];
                    System.Array.Copy(d, 0, newArray, 0, d.Length);
                    d = newArray;
                }
                bytesRead = input.Read(d, pos, d.Length - pos);
                pos      += bytesRead;

// TODO: CML - don't know what to do with this in context of asp.net
                //if (Thread.currentThread().isInterrupted())
                //    {
                //    throw new InterruptedIOException();
                //    }
            }

            bytesRead = pos + 1;

            // Perform file reading checks and throw exceptions as necessary
            if (bytesRead == 0)
            {
                throw new BiffException(BiffException.excelFileNotFound);
            }

            CompoundFile cf = new CompoundFile(d, ws);

            try
            {
                data = cf.getStream("workbook");
            }
            catch (BiffException e)
            {
                // this might be in excel 95 format - try again
                data = cf.getStream("book");
            }

            if (!workbookSettings.getPropertySetsDisabled() &&
                (cf.getNumberOfPropertySets() >
                 BaseCompoundFile.STANDARD_PROPERTY_SETS.Length))
            {
                compoundFile = cf;
            }

            cf = null;

            //if (!workbookSettings.getGCDisabled())
            //    {
            //    System.gc();
            //    }

            // Uncomment the following lines to send the pure workbook stream
            // (ie. a defragged ole stream) to an output file

            //      FileOutputStream fos = new FileOutputStream("defraggedxls");
            //      fos.write(data);
            //      fos.close();
        }