本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7587620
建立时间:2006年5月29日




[Apache(jakarta)]POI的一个bug问题
软件技术

lhwork 发表于 2006/8/11 9:58:21

key words : POI java读取Excel  java.io.IOException Unable to read entire block版本:2.5.1final错误提示:java.io.IOException Unable to read entire block出这个问题具有随机性,有时候没问题,有时候将Excel里的CellType改一下好像就没问题,但也不总是这样,真是莫名其妙.Google了一下是一个bug,重新下载src文件,将RawDataBlock.java文件的RawDataBlock(final InputStream stream)constructor覆盖:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public RawDataBlock(final InputStream stream) throws IOException    {        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];        int count = 0;        int totalBytesRead = 0;        while ((totalBytesRead < POIFSConstants.BIG_BLOCK_SIZE) &&(count != -1)) {                count = stream.read(_data, totalBytesRead,POIFSConstants.BIG_BLOCK_SIZE - totalBytesRead);                if (count != -1) {                        totalBytesRead += count;                }        }          if (count == -1) {                _eof = true;          } else {            _eof = false;        }           if ((totalBytesRead != POIFSConstants.BIG_BLOCK_SIZE) && (totalBytesRead != 0)) {            String type = " byte" + ((totalBytesRead == 1) ? (""): ("s"));            throw new IOException("Unable to read entire block; " +totalBytesRead + type + " read; expected " + POIFSConstants.BIG_BLOCK_SIZE + "bytes");        }    }打包:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->ant jar重启app,OK!说明:主要问题出在 InputStream的read上,原来的实现用ReadFully方法:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public static int readFully(InputStream in, byte[] b, int off, int len)    throws IOException    {        int total = 0;        for (;;) {            int got = in.read(b, off + total, len - total);            if (got < 0) {                return (total == 0) ? -1 : total;            } else {                total += got;                if (total == len)                    return total;            }        }    }InputStream的read不能确保返回的是最大字节数,但是另一个实现却可以:ByteInputStream所以,下面的方法也可以修改这个问题:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> // read entire stream into byte array:    ByteArrayOutputStream byteOS = new ByteArrayOutputStream();    byte[] buffer = new byte[1024];    int count;    while (count = inputStream.read(buffer)) != -1)        byteOS.append(buffer, 0, count);    byteOS.close();    byte[] allBytes = byteOS.betByteArray();// create workbook from array:InputStream byteIS = new ByteArrayInputStream(allBytes);HSSFWorkbook wb = new HSSFWorkbook(byteIS);


阅读全文(19045) | 回复(12) | 编辑 | 精华
 


回复:POI的一个bug问题
软件技术

kevin(游客)发表评论于2007/1/6 12:51:56

怎么没有人回复啊?有高手吗?


个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


回复:POI的一个bug问题
软件技术

kevin(游客)发表评论于2006/12/29 13:04:31

我试了两种方法都不行哦。 第一种:替换后报的错是一样的。 第二种:编译都过不了。说ByteArrayOutputStream没有append的方法,这一句byte[] allBytes = byteOS.betByteArray();也好象写错了,是不是该改为:byte[] allBytes = byteOS.toByteArray(); 谢谢。请看到后帮忙指正。回邮件给我kevin_pjw@21cn.com

个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


» 1 2 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144765052 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号