Bug 40318 - workbook.getBytes() method not working?
Summary: workbook.getBytes() method not working?
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL: http://jakarta.apache.org/poi/hssf/qu...
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-25 08:39 UTC by Ishan Bhatt
Modified: 2006-08-28 11:17 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ishan Bhatt 2006-08-25 08:39:39 UTC
The following code doesn't work: 

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream
( "c:\\workbook1.xls")); 
wb = new HSSFWorkbook(fs); 
FileOutputStream fileOut = new FileOutputStream("c:\\workbook2.xls"); 
byte[] bytes = wb.getBytes(); 
fileOut.write(bytes);
fileOut.close();

Whereas this does: 
 
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream
( "c:\\workbook1.xls")); 
wb = new HSSFWorkbook(fs); 
FileOutputStream fileOut = new FileOutputStream("c:\\workbook2.xls"); 
wb.write(fileOut);
fileOut.close();

My input file just contains a simple text "Hi" in the 1st cell. 

I have just replaced the line - wb.write(fileOut); 
with the lines -
byte[] bytes = wb.getBytes(); 
fileOut.write(bytes);

I think there is some problem with the wb.getBytes() method.
Comment 1 Amol Deshmukh 2006-08-28 18:17:19 UTC
The write method works because it does a couple more things than just getBytes
and write them to the stream:

    public void write(OutputStream stream)
            throws IOException
    {
        byte[] bytes = getBytes();
        POIFSFileSystem fs = new POIFSFileSystem();

        fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");

        if (preserveNodes) {
            List excepts = new ArrayList(1);
            excepts.add("Workbook");
            copyNodes(this.poifs,fs,excepts);
        }
        fs.writeFilesystem(stream);
        //poifs.writeFilesystem(stream);
    }