org.apache.poi.hdgf
Class HDGFLZW

java.lang.Object
  extended by org.apache.poi.hdgf.HDGFLZW

public class HDGFLZW
extends java.lang.Object

A decoder for the crazy LZW implementation used in Visio. According to VSDump, "it's a slightly perverted version of LZW compression, with inverted meaning of flag byte and 0xFEE as an 'initial shift'". It uses 12 bit codes (http://www.gnome.ru/projects/vsdump_en.html) Two good resources on LZW are: http://en.wikipedia.org/wiki/LZW http://marknelson.us/1989/10/01/lzw-data-compression/


Constructor Summary
HDGFLZW()
           
 
Method Summary
 byte[] compress(java.io.InputStream src)
          Compress the given input stream, returning the array of bytes of the compressed input
 void compress(java.io.InputStream src, java.io.OutputStream res)
          Performs the Visio compatible streaming LZW compression.
 byte[] decode(java.io.InputStream src)
          Decompresses the given input stream, returning the array of bytes of the decompressed input.
 void decode(java.io.InputStream src, java.io.OutputStream res)
          Perform a streaming decompression of the input.
static int fromByte(byte b)
          Given a java byte, turn it into an integer between 0 and 255 (i.e.
static byte fromInt(int b)
          Given an integer, turn it into a java byte, handling the wrapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HDGFLZW

public HDGFLZW()
Method Detail

fromInt

public static byte fromInt(int b)
Given an integer, turn it into a java byte, handling the wrapping. This is a convenience method


fromByte

public static int fromByte(byte b)
Given a java byte, turn it into an integer between 0 and 255 (i.e. handle the unwrapping). This is a convenience method


compress

public byte[] compress(java.io.InputStream src)
                throws java.io.IOException
Compress the given input stream, returning the array of bytes of the compressed input

Throws:
java.io.IOException

decode

public byte[] decode(java.io.InputStream src)
              throws java.io.IOException
Decompresses the given input stream, returning the array of bytes of the decompressed input.

Throws:
java.io.IOException

decode

public void decode(java.io.InputStream src,
                   java.io.OutputStream res)
            throws java.io.IOException
Perform a streaming decompression of the input. Works by: 1) Reading a flag byte, the 8 bits of which tell you if the following 8 codes are compressed our un-compressed 2) Consider the 8 bits in turn 3) If the bit is set, the next code is un-compressed, so add it to the dictionary and output it 4) If the bit isn't set, then read in the length and start position in the dictionary, and output the bytes there 5) Loop until we've done all 8 bits, then read in the next flag byte

Throws:
java.io.IOException

compress

public void compress(java.io.InputStream src,
                     java.io.OutputStream res)
              throws java.io.IOException
Performs the Visio compatible streaming LZW compression. TODO - Finish

Throws:
java.io.IOException


Copyright 2008 The Apache Software Foundation or its licensors, as applicable.