Hi,
I had the problems from version 1.0 to the last from CVS. When I tried read XSL 
from URL, POI throws an exception:

java.io.IOException: Unable to read entire block; 352 bytes read; expected 
512 bytes 
at 
org.apache.poi.poifs.storage.RawDataBlock.<init>(RawDataBlock.java:98) 
at 
org.apache.poi.poifs.storage.RawDataBlockList.<init>(RawDataBlockList.ja
va:88) 
at 
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.ja
va:123) 
at 
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:
175) 


The problem is, that the method stream.read reads less bytes from 
InputStream, but there wasn't still eof. BufferedInputStream didn't solve the 
problem so I tried to rewrite sourcecode of 
org.apache.poi.poifs.storage.RawDataBlock.java.  diff -u output is here 
(RawDataBlock2.java is my rewriten version):


--- RawDataBlock.java   Tue Mar 26 00:23:00 2002
+++ RawDataBlock2.java  Tue Mar 26 00:21:00 2002
@@ -1,4 +1,3 @@
-
 /* 
==============================================================
======
  * The Apache Software License, Version 1.1
  *
@@ -84,22 +83,17 @@
         throws IOException
     {
         _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
-        int count = stream.read(_data);
-
-        if (count == -1)
-        {
+        int count;
+        int countfill=0;
+        do  {    /* if use remote InputStream */
+           /* stream.read reads less bytes, try and wait to 
get another */
+           count= 
stream.read(_data,countfill,POIFSConstants.BIG_BLOCK_SIZE-
countfill);
+           if (count == -1) {
             _eof = true;
-        }
-        else if (count != POIFSConstants.BIG_BLOCK_SIZE)
-        {
-            String type = " byte" + ((count == 1) ? ("")
-                                                  : ("s"));
-
-            throw new IOException("Unable to read entire 
block; " + count
-                                  + type + " read; expected "
-                                  + 
POIFSConstants.BIG_BLOCK_SIZE + " bytes");
-        }
-        else
+             break; 
+           } else countfill+=count;
+        }  while (countfill!=POIFSConstants.BIG_BLOCK_SIZE);
+        if (count!=-1)
         {
             _eof = false;
         }


The problem is now solved, my program runs perfectly, but now I'm not sure 
if I haven't damaged the error recognition.

Tomas Kulhanek

Reply via email to