use of org.apache.poi.ddf.EscherRecord in project poi by apache.
the class AbstractEscherHolderRecord method getRecordSize.
@Override
public int getRecordSize() {
byte[] rawData = getRawData();
if (escherRecords.size() == 0 && rawData != null) {
// XXX: It should be possible to derive this without concatenating the array, too.
return rawData.length;
}
int size = 0;
for (EscherRecord r : escherRecords) {
size += r.getRecordSize();
}
return size;
}
use of org.apache.poi.ddf.EscherRecord in project poi by apache.
the class EscherRecordHolder method fillEscherRecords.
private void fillEscherRecords(byte[] data, int offset, int size) {
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
int pos = offset;
while (pos < offset + size) {
EscherRecord r = recordFactory.createRecord(data, pos);
escherRecords.add(r);
int bytesRead = r.fillFields(data, pos, recordFactory);
// There is an empty byte between each top-level record in a Word doc
pos += bytesRead + 1;
}
}
use of org.apache.poi.ddf.EscherRecord in project poi by apache.
the class EscherRecordHolder method toString.
public String toString() {
StringBuffer buffer = new StringBuffer();
if (escherRecords.size() == 0) {
buffer.append("No Escher Records Decoded").append("\n");
}
Iterator<EscherRecord> iterator = escherRecords.iterator();
while (iterator.hasNext()) {
EscherRecord r = iterator.next();
buffer.append(r);
}
return buffer.toString();
}
use of org.apache.poi.ddf.EscherRecord in project poi by apache.
the class PicturesTable method searchForPictures.
/**
* Performs a recursive search for pictures in the given list of escher records.
*
* @param escherRecords the escher records.
* @param pictures the list to populate with the pictures.
*/
private void searchForPictures(List<EscherRecord> escherRecords, List<Picture> pictures) {
for (EscherRecord escherRecord : escherRecords) {
if (escherRecord instanceof EscherBSERecord) {
EscherBSERecord bse = (EscherBSERecord) escherRecord;
EscherBlipRecord blip = bse.getBlipRecord();
if (blip != null) {
pictures.add(new Picture(blip));
} else if (bse.getOffset() > 0) {
try {
// Blip stored in delay stream, which in a word doc, is
// the main stream
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
EscherRecord record = recordFactory.createRecord(_mainStream, bse.getOffset());
if (record instanceof EscherBlipRecord) {
record.fillFields(_mainStream, bse.getOffset(), recordFactory);
blip = (EscherBlipRecord) record;
pictures.add(new Picture(blip));
}
} catch (Exception exc) {
logger.log(POILogger.WARN, "Unable to load picture from BLIB record at offset #", Integer.valueOf(bse.getOffset()), exc);
}
}
}
// Recursive call.
searchForPictures(escherRecord.getChildRecords(), pictures);
}
}
use of org.apache.poi.ddf.EscherRecord in project poi by apache.
the class TestDrawingAggregate method testIncompleteData.
/**
* when reading incomplete data ensure that the serialized bytes match the source
*/
@Test
public void testIncompleteData() throws IOException {
//EscherDgContainer and EscherSpgrContainer length exceeds the actual length of the data
String data = "H4sIAAAAAAAAAGWOOw7CQAxE32YTsSRIWSgQJSUloqSm5g4ICURBg+iBK3APGi6wBWeh9xGYbEps2WON" + "P+OWwpYeIsECMFC8S2jxNvMdlrYQ5xha5N8K6ryHdir6+avwOer5l3hq2NPYWuWN0n1dIsgfbgshuSj1" + "+2eqbvLdxQ0ndhy5KJ/lc1ZZK9okY5X/gSbrHZTH1vE/ozagTcwAAAA=";
byte[] dgBytes = decompress(data);
List<EscherRecord> records = new ArrayList<EscherRecord>();
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
int pos = 0;
while (pos < dgBytes.length) {
EscherRecord r = recordFactory.createRecord(dgBytes, pos);
int bytesRead = r.fillFields(dgBytes, pos, recordFactory);
records.add(r);
pos += bytesRead;
}
assertEquals("data was not fully read", dgBytes.length, pos);
// serialize to byte array
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (EscherRecord r : records) {
out.write(r.serialize());
}
assertEquals(HexDump.toHex(dgBytes, 10), HexDump.toHex(out.toByteArray(), 10));
}
Aggregations