You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by ni...@apache.org on 2007/06/20 00:41:35 UTC

svn commit: r548870 - in /jakarta/poi/trunk/src/scratchpad: src/org/apache/poi/hdgf/chunks/ src/org/apache/poi/hdgf/dev/ src/org/apache/poi/hdgf/streams/ testcases/org/apache/poi/hdgf/chunks/ testcases/org/apache/poi/hdgf/streams/

Author: nick
Date: Tue Jun 19 15:41:33 2007
New Revision: 548870

URL: http://svn.apache.org/viewvc?view=rev&rev=548870
Log:
Improved support for chunks and chunk streams, plus tests

Added:
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/chunks/
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/chunks/TestChunks.java   (with props)
Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/Stream.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java Tue Jun 19 15:41:33 2007
@@ -38,6 +38,21 @@
 		this.contents = contents;
 	}
 	
+	public byte[] _getContents() {
+		return contents;
+	}
+	public ChunkHeader getHeader() {
+		return header;
+	}
+	/** Gets the separator between this chunk and the next, if it exists */
+	public ChunkSeparator getSeparator() {
+		return separator;
+	}
+	/** Gets the trailer for this chunk, if it exists */
+	public ChunkTrailer getTrailer() {
+		return trailer;
+	}
+
 	/**
 	 * Returns the size of the chunk, including any
 	 *  headers, trailers and separators.

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java Tue Jun 19 15:41:33 2007
@@ -40,19 +40,48 @@
 		// Create the header
 		ChunkHeader header = 
 			ChunkHeader.createChunkHeader(version, data, offset);
+		int endOfDataPos = offset + header.getLength() + header.getSizeInBytes();
 		
+		// Check we have enough data, and tweak the header size
+		//  as required
+		if(endOfDataPos > data.length) {
+			System.err.println("Header called for " + header.getLength() +" bytes, but that would take us passed the end of the data!");
+			
+			endOfDataPos = data.length;
+			header.length = data.length - offset - header.getSizeInBytes();
+			
+			if(header.hasTrailer()) {
+				header.length -= 8;
+				endOfDataPos  -= 8;
+			}
+			if(header.hasSeparator()) {
+				header.length -= 4;
+				endOfDataPos  -= 4;
+			}
+		}
+		
+
 		// Create the trailer and separator, if required
 		ChunkTrailer trailer = null;
 		ChunkSeparator separator = null;
 		if(header.hasTrailer()) {
-			trailer = new ChunkTrailer(
-					data, header.getLength() + header.getSizeInBytes());
-			if(header.hasSeparator()) {
+			if(endOfDataPos <= data.length-8) {
+				trailer = new ChunkTrailer(
+					data, endOfDataPos);
+				endOfDataPos += 8;
+			} else {
+				System.err.println("Header claims a length to " + endOfDataPos + " there's then no space for the trailer in the data (" + data.length + ")");
+			}
+		}
+		if(header.hasSeparator()) {
+			if(endOfDataPos <= data.length-4) {
 				separator = new ChunkSeparator(
-					data, header.getLength() + header.getSizeInBytes() + 8);
+						data, endOfDataPos);
+			} else {
+				System.err.println("Header claims a length to " + endOfDataPos + " there's then no space for the separator in the data (" + data.length + ")");
 			}
 		}
-		
+
 		// Now, create the chunk
 		byte[] contents = new byte[header.getLength()];
 		System.arraycopy(data, offset+header.getSizeInBytes(), contents, 0, contents.length);

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java Tue Jun 19 15:41:33 2007
@@ -29,7 +29,7 @@
 
 		if(unknown2 == 2 && unknown3 == 0x55) { return true; }
 		if(unknown2 == 2 && unknown3 == 0x54 && type == 0xaa) { return true; }
-		if(unknown2 == 3 && unknown3 == 0x50 && type == 0xaa) { return true; }
+		if(unknown2 == 3 && unknown3 != 0x50) { return true; }
 		if(type == 0x69) { return true; }
 		
 		return false;

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java Tue Jun 19 15:41:33 2007
@@ -67,6 +67,16 @@
 		System.out.println(ind + "  Compressed is\t" + ptr.destinationCompressed());
 		System.out.println(ind + "  Stream is\t" + stream.getClass().getCanonicalName());
 		
+		byte[] db = stream._getStore()._getContents();
+		String ds = "";
+		if(db.length >= 8) {
+			for(int i=0; i<8; i++) {
+				if(i>0) ds += ", ";
+				ds += db[i];
+			}
+		}
+		System.out.println(ind + "  First few bytes are\t" + ds);
+		
 		if(stream instanceof PointerContainingStream) {
 			PointerContainingStream pcs = (PointerContainingStream)stream;
 			System.out.println(ind + "  Has " + 

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java Tue Jun 19 15:41:33 2007
@@ -30,6 +30,9 @@
 	protected ChunkStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory) {
 		super(pointer, store);
 		this.chunkFactory = chunkFactory;
+		
+		// For compressed stores, we require all of the data
+		store.copyBlockHeaderToContents();
 	}
 	
 	public Chunk[] getChunks() { return chunks; }

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java Tue Jun 19 15:41:33 2007
@@ -25,7 +25,7 @@
  * A StreamStore where the data on-disk is compressed,
  *  using the crazy Visio LZW
  */
-class CompressedStreamStore extends StreamStore {
+public class CompressedStreamStore extends StreamStore {
 	/** The raw, compressed contents */
 	private byte[] compressedContents;
 	/** 
@@ -33,6 +33,7 @@
 	 *  real contents in the de-compressed data
 	 */
 	private byte[] blockHeader = new byte[4];
+	private boolean blockHeaderInContents = false;
 	
 	protected byte[] _getCompressedContents() { return compressedContents; }
 	protected byte[] _getBlockHeader() { return blockHeader; }
@@ -54,6 +55,19 @@
 		super(decompressedData[1], 0, decompressedData[1].length);
 		blockHeader = decompressedData[0];
 	}
+	
+	/**
+	 * Some kinds of streams expect their 4 byte header to be
+	 *  on the front of the contents.
+	 * They can call this to have it sorted.
+	 */
+	protected void copyBlockHeaderToContents() {
+		if(blockHeaderInContents) return;
+		
+		prependContentsWith(blockHeader);
+		blockHeaderInContents = true;
+	}
+	
 
 	/**
 	 * Decompresses the given data, returning it as header + contents

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java Tue Jun 19 15:41:33 2007
@@ -89,7 +89,7 @@
 			// Process chunk streams into their chunks
 			if(childStreams[i] instanceof ChunkStream) {
 				ChunkStream child = (ChunkStream)childStreams[i];
-//				child.findChunks();
+				child.findChunks();
 			}
 			
 			// Recurse into pointer containing streams

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/Stream.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/Stream.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/Stream.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/Stream.java Tue Jun 19 15:41:33 2007
@@ -35,6 +35,7 @@
 	
 	public Pointer getPointer() { return pointer; }
 	protected StreamStore getStore() { return store; }
+	public StreamStore _getStore() { return store; }
 	public int _getContentsLength() { return store.getContents().length; }
 	
 	/**

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java Tue Jun 19 15:41:33 2007
@@ -21,7 +21,7 @@
  *  handles de-compressing it as required.
  * In future, may also handle writing it back out again
  */
-class StreamStore {
+public class StreamStore {
 	private byte[] contents;
 	
 	/**
@@ -32,5 +32,14 @@
 		System.arraycopy(data, offset, contents, 0, length);
 	}
 	
+	protected void prependContentsWith(byte[] b) {
+		byte[] newContents = new byte[contents.length + b.length];
+		System.arraycopy(b, 0, newContents, 0, b.length);
+		System.arraycopy(contents, 0, newContents, b.length, contents.length);
+		contents = newContents;
+	}
+	protected void copyBlockHeaderToContents() {}
+	
 	protected byte[] getContents() { return contents; }
+	public byte[] _getContents() { return contents; }
 }

Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/chunks/TestChunks.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/chunks/TestChunks.java?view=auto&rev=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/chunks/TestChunks.java (added)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/chunks/TestChunks.java Tue Jun 19 15:41:33 2007
@@ -0,0 +1,160 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hdgf.chunks;
+
+import junit.framework.TestCase;
+
+public class TestChunks extends TestCase {
+public static final byte[] data_a = new byte[] { 70, 0, 0, 0,
+	-1, -1, -1, -1, 2, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0, 
+	0, 0, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
+	-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 
+	0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+	2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 
+	0, 36, 0, 0, 0, 1, 0, 84, 24, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+	0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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-122, 0, 0, 0, 1, 0, 80, 1, 0, 0, 0, 60, 0, 0, 0, 60, 0, 0, 
+	0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+	0, 0, 0
+};
+
+	public void testChunkHeaderA() throws Exception {
+		ChunkFactory cf = new ChunkFactory(11);
+		ChunkHeader h = 
+			ChunkHeader.createChunkHeader(11, data_a, 0);
+		
+		assertTrue(h instanceof ChunkHeaderV11);
+		ChunkHeaderV11 header = (ChunkHeaderV11)h;
+		
+		assertEquals(70, header.getType());
+		assertEquals(-1, header.getId());
+		assertEquals(2, header.getUnknown1());
+		assertEquals(68, header.getLength());
+		assertEquals(0, header.getUnknown2());
+		assertEquals(0, header.getUnknown3());
+		
+		assertTrue(header.hasTrailer());
+		assertTrue(header.hasSeparator());
+	}
+	public void testChunkHeaderB() throws Exception {
+		ChunkFactory cf = new ChunkFactory(11);
+		ChunkHeader h = 
+			ChunkHeader.createChunkHeader(11, data_b, 0);
+		
+		assertTrue(h instanceof ChunkHeaderV11);
+		ChunkHeaderV11 header = (ChunkHeaderV11)h;
+		
+		assertEquals(70, header.getType());
+		assertEquals(-1, header.getId());
+		assertEquals(3, header.getUnknown1());
+		assertEquals(68, header.getLength());
+		assertEquals(0, header.getUnknown2());
+		assertEquals(0, header.getUnknown3());
+		
+		assertTrue(header.hasTrailer());
+		assertTrue(header.hasSeparator());
+	}
+	
+	public void testOneChunk() throws Exception {
+		ChunkFactory cf = new ChunkFactory(11);
+		cf.createChunk(data_a, 0);
+		cf.createChunk(data_b, 0);
+		
+		Chunk chunk = cf.createChunk(data_a, 0);
+		assertNotNull(chunk.getHeader());
+		assertNotNull(chunk.getTrailer());
+		assertNotNull(chunk.getSeparator());
+		
+		// Should be 19 + length + 8 + 4 big
+		assertEquals(68, chunk.getHeader().getLength());
+		assertEquals(68+19+8+4, chunk.getOnDiskSize());
+	}
+	
+	public void testManyChunks() throws Exception {
+		ChunkFactory cf = new ChunkFactory(11);
+		Chunk chunk;
+		int offset = 0;
+		
+		chunk = cf.createChunk(data_a, offset);
+		assertNotNull(chunk.getHeader());
+		assertNotNull(chunk.getTrailer());
+		assertNotNull(chunk.getSeparator());
+		offset += chunk.getOnDiskSize();
+		
+		chunk = cf.createChunk(data_a, offset);
+		assertNotNull(chunk.getHeader());
+		assertNotNull(chunk.getTrailer());
+		assertNotNull(chunk.getSeparator());
+		offset += chunk.getOnDiskSize();
+		
+		chunk = cf.createChunk(data_a, offset);
+		assertNotNull(chunk.getHeader());
+		assertNull(chunk.getTrailer());
+		assertNull(chunk.getSeparator());
+		offset += chunk.getOnDiskSize();
+	}
+}

Propchange: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/chunks/TestChunks.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java?view=diff&rev=548870&r1=548869&r2=548870
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java (original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hdgf/streams/TestStreamComplex.java Tue Jun 19 15:41:33 2007
@@ -73,7 +73,23 @@
 	}
 	
 	public void testChunks() {
+		Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
+		TrailerStream ts = (TrailerStream)
+			Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
 		
+		// Should be 7th one
+		Pointer chunkPtr = ts.getChildPointers()[5];
+		assertFalse(chunkPtr.destinationHasStrings());
+		assertTrue(chunkPtr.destinationHasChunks());
+		assertFalse(chunkPtr.destinationHasPointers());
+		
+		Stream stream = Stream.createStream(chunkPtr, contents, chunkFactory, ptrFactory);
+		assertNotNull(stream);
+		assertTrue(stream instanceof ChunkStream);
+		
+		// Now find the chunks within it
+		ChunkStream cs = (ChunkStream)stream;
+		cs.findChunks();
 	}
 	
 	public void testStrings() {



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