java - Oracle Blob to XLS worksheet -


edit: solved. circumvented ibatis/apachepoi writing jdbc connector database, getting blob, , dumping file. someday, i'd know why screwing - today i'm happy have behind me.

summary: i'm getting oracle blobs , using apache poi reconstitute excel binaries pass through soap service layer. .net client writing these .xls files fine, has corrupt files when writing unix directory.

detail: have excel blobs stored in oracle table. these blobs written using ibatis, , pulled using (truncated) result map.

<resultmap id="report" class="report">         <result column="content" property ="content" typehandler="blobbytearraytypehandler"/> 

the excel reports generated using apache.poi our java services. @ moment, our client (.net) queries service byte array, written windows machine without error - dumping bytes file.

these excel files fine.

the problem i'm having have new requirement should writing these files out unix file system, further processing.

all attempts @ have failed. here code samples:

private void writereportdumpbytes(report report) {     file file = new file("report.xls");     fileoutputstream fileoutputstream;     try {         fileoutputstream = new fileoutputstream(file);         fileoutputstream.write(report.getcontent());         fileoutputstream.flush();         fileoutputstream.close();     } catch (filenotfoundexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }    }  private void writereportwithencoding(report report, string encoding) {     file file = new file("report.xls");     fileoutputstream fileoutputstream;     try {         fileoutputstream = new fileoutputstream(file);         outputstreamwriter outputstreamwriter = new outputstreamwriter(fileoutputstream, encoding);                  writer out = new bufferedwriter(outputstreamwriter);         string reportbytes = new string(report.getcontent());         out.write(reportbytes.tochararray());         out.flush();         out.close();     } catch (filenotfoundexception e) {         e.printstacktrace();     } catch (unsupportedencodingexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }                }  public void writereporthssfpoifilesystem(report report) {     try {         inputstream bytestream = new bytearrayinputstream(report.getcontent());         poifsfilesystem fs = new poifsfilesystem(bytestream);         hssfworkbook workbook = new hssfworkbook(fs);                    fileoutputstream fileout = new fileoutputstream("report.xls");         workbook.write(fileout);         fileout.flush();         fileout.close();     } catch (ioexception e) {         log.error(e.getmessage(), e);     } }  private void writereportapacheio(report report) {     file file = new file("report.xls");     try {                    logreportbytes(report, "apache io");                     fileutils.writebytearraytofile(file, report.getcontent());     } catch (ioexception e) {         log.error("caught ioexception", e);     }                } 

in order diagnose this, have tried grabbing blob oracle, , saving file. in bare-bones jar executable, have been able read bytes file, , rewrite using above methods on our unix box - , work.

however, our code, excel files corrupt, or missing header information apache.poi. opening corrupt/bad binaries in text editor shows repeating pattern of 64 bytes. not valid xls binary.

something going sideways. blob valid xls binary, , getting bytes (using ibatis above) , passing them through hssfworkbook object, , trying write using methods i've shown them.

    /**  * return byte array based on workbook.  *   * @return  * @throws ioexception  */ public byte[] getcontent() throws ioexception {     bytearrayoutputstream bos = new bytearrayoutputstream();     this.workbook.write(bos);        return bos.tobytearray(); } 

the specific error i'm getting when using apache poi is:

java.io.ioexception: block[ 0 ] removed @ org.apache.poi.poifs.storage.blocklistimpl.remove(blocklistimpl.java:97) @ org.apache.poi.poifs.storage.blockallocationtablereader.fetchblocks(blockallocationtablereader.java:190) @ org.apache.poi.poifs.storage.blocklistimpl.fetchblocks(blocklistimpl.java:130) @ org.apache.poi.poifs.property.propertytable.<init>(propertytable.java:79) @ org.apache.poi.poifs.filesystem.poifsfilesystem.<init>(poifsfilesystem.java:171) 

i wrote jdbc call directly db ignoring nonsense of ibatis , apache poi. worked fine using variety of disk write methods.