From: Nick Burch Date: Tue, 25 Oct 2016 09:33:37 +0000 (+0000) Subject: Refactor child pointer logic to the factory X-Git-Tag: REL_3_16_BETA1~47 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=41d7cf537e88b7281c32b565c97e79f2becb4470;p=poi.git Refactor child pointer logic to the factory git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1766492 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java b/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java index d10f154e2e..a2c5854f73 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/pointers/Pointer.java @@ -45,6 +45,10 @@ public abstract class Pointer { } public abstract int getSizeInBytes(); + public abstract int getNumPointersOffset(byte[] data); + public abstract int getNumPointers(int offset, byte[] data); + public abstract int getPostNumPointersSkip(); + public abstract boolean destinationHasStrings(); public abstract boolean destinationHasPointers(); public abstract boolean destinationHasChunks(); diff --git a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java index 640396cf57..8506c83a97 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/pointers/PointerFactory.java @@ -31,6 +31,9 @@ public final class PointerFactory { } public int getVersion() { return version; } + /** + * Creates a single Pointer from the data at the given offset + */ public Pointer createPointer(byte[] data, int offset) { Pointer p; if(version >= 6) { @@ -57,39 +60,25 @@ public final class PointerFactory { } /** - * In a {@link PointerContainingStream}, where would the - * number of child pointers be stored for this kind of Pointer? + * Parsers the {@link PointerContainingStream} contents and + * creates all the child Pointers for it */ - public int identifyNumPointersOffset(Pointer pointer, byte[] data) { - if (pointer instanceof PointerV6) { - // V6 stores it as the first value in the stream - return (int)LittleEndian.getUInt(data, 0); - } else if (pointer instanceof PointerV5) { - // V5 uses fixed offsets - switch (pointer.type) { - case 0x1d: - case 0x4e: - return 0x24-6; - case 0x1e: - return 0x3c-6; - case 0x14: - return 0x88-6; - } - return 10; - } else { - throw new IllegalArgumentException("Unsupported Pointer type " + pointer); - } - } - - public int identifyNumPointers(Pointer pointer, int offset, byte[] data) { - if (pointer instanceof PointerV6) { - // V6 stores it a 32 bit number at the offset - return (int)LittleEndian.getUInt(data, offset); - } else if (pointer instanceof PointerV5) { - // V5 stores it as a 16 bit number at the offset - return LittleEndian.getShort(data, offset); - } else { - throw new IllegalArgumentException("Unsupported Pointer type " + pointer); + public Pointer[] createContainerPointers(Pointer parent, byte[] data) { + // Where in the stream does the "number of pointers" offset live? + int numPointersOffset = parent.getNumPointersOffset(data); + // How many do we have? + int numPointers = parent.getNumPointers(numPointersOffset, data); + // How much to skip for the num pointers + any extra data? + int skip = parent.getPostNumPointersSkip(); + + // Create + int pos = numPointersOffset + skip; + Pointer[] childPointers = new Pointer[numPointers]; + for(int i=0; i