diff options
author | Nick Burch <nick@apache.org> | 2011-03-05 15:25:39 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2011-03-05 15:25:39 +0000 |
commit | f05c5454fcff4f5f4e3d0661df1aa996de2da603 (patch) | |
tree | 66286182b558985aa8756418f1e721195aeb06d2 /src/scratchpad | |
parent | 5805f3b66001219a382427f995b323fcba40d700 (diff) | |
download | poi-f05c5454fcff4f5f4e3d0661df1aa996de2da603.tar.gz poi-f05c5454fcff4f5f4e3d0661df1aa996de2da603.zip |
Two more differences between the LZW in HDGF and HMEF:
* Little Endian vs Big Endian storage of the code position
* Initial dictionary position is the end of pre-fill, if there is one, rather than always being position 0
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1078300 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
3 files changed, 23 insertions, 12 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZW.java b/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZW.java index f122c40f17..e6d4aa2e65 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZW.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/HDGFLZW.java @@ -37,8 +37,10 @@ import org.apache.poi.util.LZWDecompresser; */ public class HDGFLZW extends LZWDecompresser { public HDGFLZW() { - // We're the wrong way round! - super(false, 3); + // Out flag is the wrong way round! + // Length wise, we're 3 longer than we say, so the max len is 19 + // Endian wise, we're little endian, so 0x1234 is pos 0x312 + super(false, 3, false); } /** @@ -63,12 +65,13 @@ public class HDGFLZW extends LZWDecompresser { } return pntr; } - + /** * We want an empty dictionary, so do nothing */ @Override - protected void populateDictionary(byte[] dict) { + protected int populateDictionary(byte[] dict) { + return 0; } /** diff --git a/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java b/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java index 81218bc9ba..70c3e59295 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java +++ b/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java @@ -54,7 +54,10 @@ public final class CompressedRTF extends LZWDecompresser { "{\\colortbl\\red0\\green0\\blue0\n\r\\par \\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx"; public CompressedRTF() { - super(true, 2); + // Out flag has the normal meaning + // Length wise, we're 2 longer than we say, so the max len is 18 + // Endian wise, we're big endian, so 0x1234 is pos 0x123 + super(true, 2, true); } public void decompress(InputStream src, OutputStream res) throws IOException { @@ -80,17 +83,24 @@ public final class CompressedRTF extends LZWDecompresser { super.decompress(src, res); } + /** + * We use regular dictionary offsets, so no + * need to change anything + */ @Override protected int adjustDictionaryOffset(int offset) { - // TODO Do we need to change anything? - return 0; + return offset; } @Override - protected void populateDictionary(byte[] dict) { + protected int populateDictionary(byte[] dict) { try { + // Copy in the RTF constants byte[] preload = LZW_RTF_PRELOAD.getBytes("US-ASCII"); System.arraycopy(preload, 0, dict, 0, preload.length); + + // Start adding new codes after the constants + return preload.length; } catch(UnsupportedEncodingException e) { throw new RuntimeException("Your JVM is broken as it doesn't support US ASCII"); } diff --git a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java index ad8f6692b1..36991c43cf 100644 --- a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java +++ b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java @@ -93,7 +93,7 @@ public final class TestCompressedRTF extends TestCase { * Check that we can decode the first 8 codes * (1 flag byte + 8 codes) */ - public void DISABLEDtestFirstBlock() throws Exception { + public void testFirstBlock() throws Exception { HMEFMessage msg = new HMEFMessage( _samples.openResourceAsStream("quick-winmail.dat") ); @@ -112,7 +112,6 @@ public final class TestCompressedRTF extends TestCase { String decompStr = new String(decomp, "ASCII"); // Test -System.err.println(decompStr); assertEquals(block1.length(), decomp.length); assertEquals(block1, decompStr); } @@ -121,7 +120,7 @@ System.err.println(decompStr); * Check that we can decode the first 16 codes * (flag + 8 codes, flag + 8 codes) */ - public void DISABLEDtestFirstTwoBlocks() throws Exception { + public void testFirstTwoBlocks() throws Exception { HMEFMessage msg = new HMEFMessage( _samples.openResourceAsStream("quick-winmail.dat") ); @@ -140,7 +139,6 @@ System.err.println(decompStr); String decompStr = new String(decomp, "ASCII"); // Test -System.err.println(decompStr); assertEquals(block2.length(), decomp.length); assertEquals(block2, decompStr); } |