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]);
}
}
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);
}
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);
}
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);
}
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());
}
Aggregations