public File(InputStream is,
WorkbookSettings ws) throws BiffException, IOException {
// Initialize the file sizing parameters from the settings
workbookSettings = ws;
initialFileSize = workbookSettings.getInitialFileSize();
arrayGrowSize = workbookSettings.getArrayGrowSize();
byte[] d = new byte[initialFileSize];
int bytesRead = is.read(d);
int pos = bytesRead;
// Handle thread interruptions, in case the user keeps pressing
// the Submit button from a browser. Thanks to Mike Smith for this
if (Thread.currentThread().isInterrupted())
{
throw new InterruptedIOException();
}
while (bytesRead != -1)
{
if (pos >= d.length)
{
// Grow the array
byte[] newArray = new byte[d.length + arrayGrowSize];
System.arraycopy(d, 0, newArray, 0, d.length);
d = newArray;
}
bytesRead = is.read(d, pos, d.length - pos);
pos += bytesRead;
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();
}
Constructs a file from the input stream Parameters:
is - the input stream
ws - the workbook settings
Throws:
IOException -
BiffException -
- exception:
IOException -
- exception:
BiffException -
|