From: Nick Burch Date: Mon, 18 Jun 2007 22:26:04 +0000 (+0000) Subject: Basic support for a few key kinds of streams, and tests to go with this X-Git-Tag: REL_3_0_1_RC3~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0f0d2aaf989850f3ace238eab7ef014415a2dd06;p=poi.git Basic support for a few key kinds of streams, and tests to go with this git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@548511 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.xml b/build.xml index 7405039592..cb5c6d6494 100644 --- a/build.xml +++ b/build.xml @@ -495,6 +495,7 @@ under the License. + @@ -526,7 +527,8 @@ under the License. - + + diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java index 7edb389025..df93d9d5e5 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java @@ -1,6 +1,19 @@ -/** - * - */ +/* ==================================================================== + 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.streams; import java.io.ByteArrayInputStream; @@ -8,6 +21,10 @@ import java.io.IOException; import org.apache.poi.hdgf.LZW4HDGF; +/** + * A StreamStore where the data on-disk is compressed, + * using the crazy Visio LZW + */ class CompressedStreamStore extends StreamStore { /** The raw, compressed contents */ private byte[] compressedContents; diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java new file mode 100644 index 0000000000..fc1442a571 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/PointerContainingStream.java @@ -0,0 +1,94 @@ +/* ==================================================================== + 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.streams; + +import org.apache.poi.hdgf.pointers.Pointer; +import org.apache.poi.hdgf.pointers.PointerFactory; +import org.apache.poi.util.LittleEndian; + +/** + * A stream that holds pointers, possibly in addition to some + * other data too. + */ +public class PointerContainingStream extends Stream { + private Pointer[] childPointers; + private Stream[] childStreams; + + private PointerFactory pointerFactory; + private int numPointersLocalOffset; + + protected PointerContainingStream(Pointer pointer, StreamStore store, PointerFactory pointerFactory) { + super(pointer, store); + this.pointerFactory = pointerFactory; + + // Find the offset to the number of child pointers we have + // This ought to be the first thing stored in us + numPointersLocalOffset = (int)LittleEndian.getUInt( + store.getContents(), 0 + ); + + // Generate the objects for the pointers we contain + int numPointers = (int)LittleEndian.getUInt( + store.getContents(), numPointersLocalOffset + ); + childPointers = new Pointer[numPointers]; + + // After the number of pointers is another (unknown) + // 4 byte value + int pos = numPointersLocalOffset + 4 + 4; + + // Now create the pointer objects + for(int i=0; i 4 -> 5 -> 1 -> 0 == String + assertNotNull(ts.getPointedToStreams()[8]); + assertTrue(ts.getPointedToStreams()[8] instanceof PointerContainingStream); + + PointerContainingStream s8 = + (PointerContainingStream)ts.getPointedToStreams()[8]; + assertNotNull(s8.getPointedToStreams()); + + assertNotNull(s8.getPointedToStreams()[4]); + assertTrue(s8.getPointedToStreams()[4] instanceof PointerContainingStream); + + PointerContainingStream s84 = + (PointerContainingStream)s8.getPointedToStreams()[4]; + assertNotNull(s84.getPointedToStreams()); + + assertNotNull(s84.getPointedToStreams()[5]); + assertTrue(s84.getPointedToStreams()[5] instanceof PointerContainingStream); + + PointerContainingStream s845 = + (PointerContainingStream)s84.getPointedToStreams()[5]; + assertNotNull(s845.getPointedToStreams()); + + assertNotNull(s845.getPointedToStreams()[1]); + assertTrue(s845.getPointedToStreams()[1] instanceof PointerContainingStream); + + PointerContainingStream s8451 = + (PointerContainingStream)s845.getPointedToStreams()[1]; + assertNotNull(s8451.getPointedToStreams()); + + assertNotNull(s8451.getPointedToStreams()[0]); + assertTrue(s8451.getPointedToStreams()[0] instanceof StringsStream); + assertTrue(s8451.getPointedToStreams()[1] instanceof StringsStream); + } +}