FileDocCategorySizeDatePackage
CompressedStreamStore.javaAPI DocApache Poi 3.0.13156Tue Jun 19 21:52:08 BST 2007org.apache.poi.hdgf.streams

CompressedStreamStore

public class CompressedStreamStore extends StreamStore
A StreamStore where the data on-disk is compressed, using the crazy Visio LZW

Fields Summary
private byte[]
compressedContents
The raw, compressed contents
private byte[]
blockHeader
We're not sure what this is, but it comes before the real contents in the de-compressed data
private boolean
blockHeaderInContents
Constructors Summary
protected CompressedStreamStore(byte[] data, int offset, int length)
Creates a new compressed StreamStore, which will handle the decompression.

		this(decompress(data,offset,length));
		
		compressedContents = new byte[length];
		System.arraycopy(data, offset, compressedContents, 0, length);
	
private CompressedStreamStore(byte[] decompressedData)
Handles passing the de-compressed data onto our superclass.

		super(decompressedData[1], 0, decompressedData[1].length);
		blockHeader = decompressedData[0];
	
Methods Summary
protected byte[]_getBlockHeader()

 return blockHeader; 
protected byte[]_getCompressedContents()

	
	    return compressedContents; 
protected voidcopyBlockHeaderToContents()
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.

		if(blockHeaderInContents) return;
		
		prependContentsWith(blockHeader);
		blockHeaderInContents = true;
	
public static byte[][]decompress(byte[] data, int offset, int length)
Decompresses the given data, returning it as header + contents

		ByteArrayInputStream bais = new ByteArrayInputStream(data, offset, length);
		
		// Decompress
		LZW4HDGF lzw = new LZW4HDGF();
		byte[] decompressed = lzw.decode(bais);
		
		// Split into header and contents
		byte[][] ret = new byte[2][];
		ret[0] = new byte[4];
		ret[1] = new byte[decompressed.length - 4];
		
		System.arraycopy(decompressed, 0, ret[0], 0, 4);
		System.arraycopy(decompressed, 4, ret[1], 0, ret[1].length);
		
		// All done
		return ret;