public COSObject getObject(final COSKey key) { try { COSObject obj = this.body.get(key); if (!obj.empty()) { return obj; } COSObject newObj = this.reader.getObject(key); if (newObj == null) { return new COSObject(); } this.body.set(key, newObj); return this.body.get(key); } catch (IOException e) { //TODO : maybe not runtime, maybe no exception at all throw new RuntimeException("Error while parsing object : " + key.getNumber() + " " + key.getGeneration(), e); } }
public COSDocument(final PDDocument document) { this.doc = document; this.header = new COSHeader(); this.body = new COSBody(); this.xref = new COSXRefTable(); this.trailer = new COSTrailer(); this.firstTrailer = new COSTrailer(); this.lastTrailer = new COSTrailer(); this.linearized = false; this.isNew = true; this.changedObjects = new ArrayList<>(); this.addedObjects = new ArrayList<>(); this.resourceHandler = new FileResourceHandler(); }
public void setObject(final COSKey key, final COSObject obj) { this.body.set(key, obj); this.xref.newKey(key); }
private void initCOSDocument(final PDDocument document) { this.doc = document; this.body = new COSBody(); this.header = this.reader.getHeader(); this.xref = new COSXRefTable(); this.xref.set(this.reader.getKeys()); this.trailer = reader.getTrailer(); this.firstTrailer = reader.getFirstTrailer(); this.lastTrailer = reader.getLastTrailer(); this.linearized = reader.isLinearized(); this.changedObjects = new ArrayList<>(); this.addedObjects = new ArrayList<>(); }
public COSKey setObject(COSObject obj) { COSKey key = obj.getKey(); //TODO : fix this method for document save if (key == null) { key = this.xref.next(); this.body.set(key, obj.isIndirect() ? obj.getDirect() : obj); obj = COSIndirect.construct(key, this); } this.xref.newKey(key); return key; }
public Map<COSKey, COSObject> getObjectsMap() { Map<COSKey, COSObject> result = new HashMap<>(); for (COSKey key : this.xref.getAllKeys()) { COSObject obj = this.body.get(key); if (!obj.empty()) { result.put(key, obj); } else { try { COSObject newObj = this.reader.getObject(key); this.body.set(key, newObj); result.put(key, newObj); } catch (IOException e) { LOGGER.log(Level.FINE, "Error while parsing object : " + key.getNumber() + " " + key.getGeneration(), e); } } } return result; }
public List<COSObject> getObjects() { List<COSObject> result = new ArrayList<>(); for (COSKey key : this.xref.getAllKeys()) { COSObject obj = this.body.get(key); if (!obj.empty()) { result.add(obj); } else { try { COSObject newObj = this.reader.getObject(key); this.body.set(key, newObj); result.add(newObj); } catch (IOException e) { LOGGER.log(Level.FINE, "Error while parsing object : " + key.getNumber() + " " + key.getGeneration(), e); } catch (StackOverflowError e) { // TODO: double check this StackOverfrow catching throw new LoopedException("Loop in getting object from reader", e); } } } return result; }
public List<COSObject> getObjectsByType(ASAtom type) { List<COSObject> result = new ArrayList<>(); for (COSKey key : this.xref.getAllKeys()) { COSObject obj = this.body.get(key); if (!obj.empty()) { addObjectWithTypeKeyCheck(result, obj, type); } else { try { COSObject newObj = this.reader.getObject(key); this.body.set(key, newObj); addObjectWithTypeKeyCheck(result, obj, type); } catch (IOException e) { LOGGER.log(Level.FINE, "Error while parsing object : " + key.getNumber() + " " + key.getGeneration(), e); } } } return result; }