예제 #1
0
파일: File.cs 프로젝트: morninn/PetSof
        private void createDataOutput()
        {
            if (workbookSettings.getUseTemporaryFileDuringWrite())
            {
                data = new FileDataOutput(workbookSettings.getTemporaryFileDuringWriteDirectory());
            }
            else
            {
                initialFileSize = workbookSettings.getInitialFileSize();
                arrayGrowSize   = workbookSettings.getArrayGrowSize();

                data = new MemoryDataOutput(initialFileSize, arrayGrowSize);
            }
        }
예제 #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();
        }