You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/05/05 17:10:17 UTC

svn commit: r941334 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/poifs/common/ java/org/apache/poi/poifs/dev/ java/org/apache/poi/poifs/storage/ testcases/org/apache/poi/poifs/filesystem/

Author: nick
Date: Wed May  5 15:10:17 2010
New Revision: 941334

URL: http://svn.apache.org/viewvc?rev=941334&view=rev
Log:
Hopefully finish fixing bug #49139 - track down another subtle hard coding of 512, and switch to using the big block size variable

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java
    poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java
    poi/trunk/src/java/org/apache/poi/poifs/storage/DocumentBlock.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=941334&r1=941333&r2=941334&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed May  5 15:10:17 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49139 - Properly support 4k big block size in POIFS</action>
            <action dev="POI-DEVELOPERS" type="fix">48936 - Avoid writing malformed CDATA blocks in sharedStrings.xml</action>
            <action dev="POI-DEVELOPERS" type="add">49026 - Added implementation for TEXT()  </action>
            <action dev="POI-DEVELOPERS" type="add">49025 - Added implementation for TRUNC()  </action>

Modified: poi/trunk/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java?rev=941334&r1=941333&r2=941334&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/common/POIFSBigBlockSize.java Wed May  5 15:10:17 2010
@@ -38,6 +38,12 @@ public final class POIFSBigBlockSize
       return bigBlockSize;
    }
    
+   /**
+    * Returns the value that gets written into the 
+    *  header.
+    * Is the power of two that corresponds to the
+    *  size of the block, eg 512 => 9
+    */
    public short getHeaderValue() {
       return headerValue;
    }

Modified: poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java?rev=941334&r1=941333&r2=941334&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java Wed May  5 15:10:17 2010
@@ -149,6 +149,8 @@ public class POIFSHeaderDumper {
             bnS = "DI Fat Block";
          } else if(bn == POIFSConstants.FAT_SECTOR_BLOCK) {
             bnS = "Normal Fat Block";
+         } else if(bn == POIFSConstants.UNUSED_BLOCK) {
+            bnS = "Block Not Used (Free)";
          }
          
          System.out.println("  Block  # " + i + " -> " + bnS);

Modified: poi/trunk/src/java/org/apache/poi/poifs/storage/DocumentBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/storage/DocumentBlock.java?rev=941334&r1=941333&r2=941334&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/storage/DocumentBlock.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/storage/DocumentBlock.java Wed May  5 15:10:17 2010
@@ -32,10 +32,6 @@ import org.apache.poi.util.IOUtils;
  * @author Marc Johnson (mjohnson at apache dot org)
  */
 public final class DocumentBlock extends BigBlock {
-    private static final int BLOCK_SHIFT = 9;
-    private static final int BLOCK_SIZE = 1 << BLOCK_SHIFT;
-    private static final int BLOCK_MASK = BLOCK_SIZE-1;
-
     private static final byte _default_value = ( byte ) 0xFF;
     private byte[]            _data;
     private int               _bytes_read;
@@ -165,6 +161,17 @@ public final class DocumentBlock extends
     }
 
     public static DataInputBlock getDataInputBlock(DocumentBlock[] blocks, int offset) {
+        if(blocks == null || blocks.length == 0) {
+           return null;
+        }
+        
+        // Key things about the size of the block
+        POIFSBigBlockSize bigBlockSize = blocks[0].bigBlockSize;
+        int BLOCK_SHIFT = bigBlockSize.getHeaderValue();
+        int BLOCK_SIZE = bigBlockSize.getBigBlockSize();
+        int BLOCK_MASK = BLOCK_SIZE - 1;
+
+        // Now do the offset lookup
         int firstBlockIndex = offset >> BLOCK_SHIFT;
         int firstBlockOffset= offset & BLOCK_MASK;
         return new DataInputBlock(blocks[firstBlockIndex]._data, firstBlockOffset);

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=941334&r1=941333&r2=941334&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Wed May  5 15:10:17 2010
@@ -177,9 +177,8 @@ public final class TestPOIFSFileSystem e
 	/**
 	 * Most OLE2 files use 512byte blocks. However, a small number
 	 *  use 4k blocks. Check that we can open these.
-	 * DISABLED until we fix the bug with DocumentBlocks on 4k sizes
 	 */
-	public void DISABLEDtest4KBlocks() throws Exception {
+	public void test4KBlocks() throws Exception {
       POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
 	   InputStream inp = _samples.openResourceAsStream("BlockSize4096.zvi");
 	   
@@ -219,7 +218,8 @@ public final class TestPOIFSFileSystem e
 	      if(entry instanceof DirectoryEntry) {
 	         checkAllDirectoryContents((DirectoryEntry)entry);
 	      } else {
-	         DocumentInputStream dis = new DocumentInputStream((DocumentNode) entry);
+	         DocumentNode doc = (DocumentNode) entry;
+	         DocumentInputStream dis = new DocumentInputStream(doc);
 	         int numBytes = dis.available();
 	         byte[] data = new byte [numBytes];
             dis.read(data);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org