Search in sources :

Example 1 with Pointer

use of org.apache.poi.hdgf.pointers.Pointer in project poi by apache.

the class TestStreamBasics method testCompressedStream.

@Test
public void testCompressedStream() {
    // Create a fake pointer
    Pointer ptr = new TestPointer(true, 0, compressedStream.length, -1, (short) -1);
    // Now the stream
    Stream stream = Stream.createStream(ptr, compressedStream, null, null);
    // Check
    assertNotNull(stream.getPointer());
    assertNotNull(stream.getStore());
    assertTrue(stream.getStore() instanceof CompressedStreamStore);
    assertTrue(stream instanceof UnknownStream);
    // Check the stream store
    CompressedStreamStore ss = (CompressedStreamStore) stream.getStore();
    assertEquals(4, ss._getBlockHeader().length);
    assertEquals(compressedStream.length, ss._getCompressedContents().length);
    assertEquals(uncompressedStream.length, ss.getContents().length);
    for (int i = 0; i < uncompressedStream.length; i++) {
        assertEquals(uncompressedStream[i], ss.getContents()[i]);
    }
}
Also used : Pointer(org.apache.poi.hdgf.pointers.Pointer) Test(org.junit.Test)

Example 2 with Pointer

use of org.apache.poi.hdgf.pointers.Pointer in project poi by apache.

the class TestStreamBasics method testUncompressedStream.

@Test
public void testUncompressedStream() {
    // Create a fake pointer
    Pointer ptr = new TestPointer(false, 0, uncompressedStream.length, -1, (short) -1);
    // Now the stream
    Stream stream = Stream.createStream(ptr, uncompressedStream, null, null);
    // Check
    assertNotNull(stream.getPointer());
    assertNotNull(stream.getStore());
    assertFalse(stream.getStore() instanceof CompressedStreamStore);
    assertTrue(stream instanceof UnknownStream);
}
Also used : Pointer(org.apache.poi.hdgf.pointers.Pointer) Test(org.junit.Test)

Example 3 with Pointer

use of org.apache.poi.hdgf.pointers.Pointer in project poi by apache.

the class TestStreamComplex method testTrailerContents.

@Test
public void testTrailerContents() {
    Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
    TrailerStream ts = (TrailerStream) Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
    assertNotNull(ts.getChildPointers());
    assertNull(ts.getPointedToStreams());
    assertEquals(20, ts.getChildPointers().length);
    ts.findChildren(contents);
    assertNotNull(ts.getChildPointers());
    assertNotNull(ts.getPointedToStreams());
    assertEquals(20, ts.getChildPointers().length);
    assertEquals(20, ts.getPointedToStreams().length);
    // Step down:
    // 8 -> 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);
}
Also used : Pointer(org.apache.poi.hdgf.pointers.Pointer) Test(org.junit.Test)

Example 4 with Pointer

use of org.apache.poi.hdgf.pointers.Pointer in project poi by apache.

the class TestStreamBugs method testGetChildren.

@Test
public void testGetChildren() {
    Pointer trailerPointer = ptrFactory.createPointer(contents, 0x24);
    TrailerStream trailer = (TrailerStream) Stream.createStream(trailerPointer, contents, chunkFactory, ptrFactory);
    // Get without recursing
    Pointer[] ptrs = trailer.getChildPointers();
    for (Pointer ptr : ptrs) {
        Stream.createStream(ptr, contents, chunkFactory, ptrFactory);
    }
    // Get with recursing into chunks
    for (Pointer ptr : ptrs) {
        Stream stream = Stream.createStream(ptr, contents, chunkFactory, ptrFactory);
        if (stream instanceof ChunkStream) {
            ChunkStream cStream = (ChunkStream) stream;
            cStream.findChunks();
        }
    }
    // Get with recursing into chunks and pointers
    for (Pointer ptr : ptrs) {
        Stream stream = Stream.createStream(ptr, contents, chunkFactory, ptrFactory);
        if (stream instanceof PointerContainingStream) {
            PointerContainingStream pStream = (PointerContainingStream) stream;
            pStream.findChildren(contents);
        }
    }
    trailer.findChildren(contents);
}
Also used : Pointer(org.apache.poi.hdgf.pointers.Pointer) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with Pointer

use of org.apache.poi.hdgf.pointers.Pointer in project poi by apache.

the class TestStreamComplex method testTrailer.

/**
	 * Test creating the trailer, but not looking for children
	 */
@Test
public void testTrailer() {
    // Find the trailer
    Pointer trailerPtr = ptrFactory.createPointer(contents, trailerPointerAt);
    assertEquals(20, trailerPtr.getType());
    assertEquals(trailerDataAt, trailerPtr.getOffset());
    Stream stream = Stream.createStream(trailerPtr, contents, chunkFactory, ptrFactory);
    assertTrue(stream instanceof TrailerStream);
    TrailerStream ts = (TrailerStream) stream;
    assertNotNull(ts.getChildPointers());
    assertNull(ts.getPointedToStreams());
    assertEquals(20, ts.getChildPointers().length);
    assertEquals(0x16, ts.getChildPointers()[0].getType());
    assertEquals(0x17, ts.getChildPointers()[1].getType());
    assertEquals(0x17, ts.getChildPointers()[2].getType());
    assertEquals(0xff, ts.getChildPointers()[3].getType());
}
Also used : Pointer(org.apache.poi.hdgf.pointers.Pointer) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

Pointer (org.apache.poi.hdgf.pointers.Pointer)13 Test (org.junit.Test)10 InputStream (java.io.InputStream)5 Chunk (org.apache.poi.hdgf.chunks.Chunk)2 PointerContainingStream (org.apache.poi.hdgf.streams.PointerContainingStream)2 Stream (org.apache.poi.hdgf.streams.Stream)2 PrintStream (java.io.PrintStream)1 ChunkStream (org.apache.poi.hdgf.streams.ChunkStream)1 StringsStream (org.apache.poi.hdgf.streams.StringsStream)1 TrailerStream (org.apache.poi.hdgf.streams.TrailerStream)1