public void visitFromStream(COSStream obj) { visitFromDictionary(obj); this.copy.assign(COSStream.construct((COSDictionary) this.copy.get(), obj.getData(), obj.getFilterFlags())); }
/** * Default constructor * @param stream greenfield COSStream */ public GFCosStream(COSStream stream) { super(stream, COS_STREAM_TYPE); this.length = parseLength(stream); COSObject fileSpec = stream.getKey(ASAtom.F); this.fileSpec = fileSpec.empty() ? null : fileSpec.toString(); this.fFilter = parseFilters(stream.getKey(ASAtom.F_FILTER).get()); String fDecodeParams = stream.getStringKey(ASAtom.F_DECODE_PARMS); this.fDecodeParams = fDecodeParams == null || fDecodeParams.isEmpty() ? null : fDecodeParams; this.streamKeywordCRLFCompliant = stream.isStreamKeywordCRLFCompliant().booleanValue(); this.endstreamKeywordEOLCompliant = stream.isEndstreamKeywordCRLFCompliant().booleanValue(); this.isLengthCorrect = this.length != null && this.length.equals(stream.getRealStreamSize()); }
@Override public String getSubtype() { if (this.stream != null) { ASAtom s = this.stream.getNameKey(ASAtom.SUBTYPE); return s == null ? null : s.getValue(); } return null; }
private void parseCMapFile() { String cMapName = parentStream.getStringKey(ASAtom.CMAPNAME); try (ASInputStream data = this.parentStream.getData(COSStream.FilterFlags.DECODE)) { cMap = CMapFactory.getCMap(cMapName == null ? "" : cMapName, data); } catch (IOException e) { LOGGER.log(Level.WARNING, "Exception while parsing cmap file", e); } } }
@Override public ASInputStream getData(final FilterFlags filterFlags) { try { if (filterFlags == FilterFlags.RAW_DATA || this.flags != FilterFlags.RAW_DATA) { this.stream.reset(); return this.stream; } ASInputStream result = getFilters().getInputStream( ASInputStream.createStreamFromStream(stream), this.getKey(ASAtom.DECODE_PARMS)); result.reset(); return result; } catch (IOException e) { LOGGER.log(Level.FINE, "Can't get stream data", e); return null; } }
this.getSubtype() == ASAtom.CID_FONT_TYPE2) { COSStream trueTypeFontFile = fontDescriptor.getFontFile2(); COSKey key = trueTypeFontFile.getObjectKey(); COSObject cidToGIDMap = this.getCIDToGIDMap(); String fontProgramID = FontProgramIDGenerator.getCIDFontType2ProgramID(key, this.cMap, cidToGIDMap); this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = trueTypeFontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new CIDFontType2Program( fontData, this.cMap, cidToGIDMap); COSName subtype = (COSName) fontFile.getKey(ASAtom.SUBTYPE).getDirectBase(); COSKey key = fontFile.getObjectKey(); try { boolean isSubset = this.isSubset(); this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = fontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new CFFFontProgram(fontData, this.cMap, isSubset); StaticResources.cacheFontProgram(fontProgramID, this.fontProgram); this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = fontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new OpenTypeFontProgram( fontData, isCFF, isSymbolic, encoding,
@Override public InputStream getData() { return file == null ? null : file.getData(COSStream.FilterFlags.DECODE); } }
public COSFilters getFilters() { return new COSFilters(getKey(ASAtom.FILTER)); }
return this.equals(((COSObject) obj).get()); for(Map.Entry<ASAtom, COSObject> entry : this.getEntrySet()) { if(entry.getKey() == ASAtom.FILTER || entry.getKey() == ASAtom.DECODE_PARMS || continue; COSBase cosBase = that.getKey(entry.getKey()).get(); if(!entry.getValue().get().equals(cosBase, checkedObjects)) { return false; for(Map.Entry<ASAtom, COSObject> entry : that.getEntrySet()) { if(entry.getKey() == ASAtom.FILTER || entry.getKey() == ASAtom.DECODE_PARMS || continue; COSBase cosBase = this.getKey(entry.getKey()).get(); if(!entry.getValue().get().equals(cosBase, checkedObjects)) { return false; if (stream != null ? !equalsStreams(stream, that.stream) : that.stream != null) return false; } catch (IOException e) {
@Override public int removeFiltersForAllMetadataObjects() { int res = 0; List<COSObject> objects = this.document.getDocument().getObjectsByType(ASAtom.METADATA); List<COSStream> metas = new ArrayList<>(); for (COSObject obj : objects) { if (obj.getType() == COSObjType.COS_STREAM) { metas.add((COSStream) obj.getDirectBase()); } else { LOGGER.log(Level.SEVERE, "Found non-stream Metadata dictionary."); } } for (COSStream stream : metas) { if (stream.getFilters().size() > 0) { try { stream.setFilters(new COSFilters()); res++; } catch (IOException e) { LOGGER.log(Level.FINE, "Error when removing filter from stream", e); return -1; } } } isUnfiltered = res > 0; return res; }
public void visitFromStream(COSStream obj) { long length; ASInputStream in = obj.getData(); if (obj.getFilterFlags() == COSStream.FilterFlags.DECODE || obj.getFilterFlags() == COSStream.FilterFlags.DECRYPT_AND_DECODE) { obj.setIntegerKey(ASAtom.LENGTH, getASInputStreamLength(in)); } catch (IOException e) { LOGGER.log(Level.FINE, "Can't calculate length of ASInputStream", e); obj.setLength(length);
/** * This is an entry point for parsing xref stream and trailer. * * @throws IOException */ void parseStreamAndTrailer() throws IOException { try { xrefInputStream = xrefCOSStream.getData(COSStream.FilterFlags.DECODE); fieldSizes = (COSArray) xrefCOSStream.getKey(ASAtom.W).getDirectBase(); if (fieldSizes.size() != 3) { throw new IOException("W array in xref should have 3 elements."); } initializeIndex(); initializeObjIDs(); parseStream(); setTrailer(); } finally { xrefInputStream.close(); } }
COSKey key = type1FontFile.getObjectKey(); try { if (fontFileType == ASAtom.FONT_FILE) { this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = type1FontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new Type1FontProgram(fontData); StaticResources.cacheFontProgram(fontProgramID, this.fontProgram); ASAtom subtype = type1FontFile.getNameKey(ASAtom.SUBTYPE); boolean isSubset = this.isSubset(); if (subtype == ASAtom.TYPE1C) { this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = type1FontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new CFFFontProgram(fontData, null, isSubset); StaticResources.cacheFontProgram(fontProgramID, this.fontProgram); this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = type1FontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new OpenTypeFontProgram(fontData, true, isSymbolic, encoding, null, isSubset);
@Override public boolean setData(final ASInputStream stream) { COSFilters filters = getFilters(); if (filters.empty()) { return setData(stream, FilterFlags.RAW_DATA); } try (InternalOutputStream fileWithData = InternalOutputStream.getInternalOutputStream()) { ASOutputStream encoder = filters.getOutputStream(fileWithData); encoder.write(stream); File encodedDataFile = fileWithData.getFile(); return setData(new InternalInputStream(encodedDataFile, true), FilterFlags.RAW_DATA); } catch (IOException e) { LOGGER.log(Level.FINE, "Can not set data", e); return false; } }
public static COSObject construct(final COSDictionary dictionary, final ASInputStream stream) { return construct(dictionary, stream, FilterFlags.RAW_DATA); }
public void setFilters(final COSFilters filters) throws IOException { try (ASInputStream decoded = this.getData(COSStream.FilterFlags.DECODE); SeekableInputStream unfilteredData = SeekableInputStream.getSeekableStream(decoded)) { InternalOutputStream fileWithData = InternalOutputStream.getInternalOutputStream(); setKey(ASAtom.FILTER, filters.getObject()); ASOutputStream encoder = filters.getOutputStream(fileWithData); encoder.write(unfilteredData); File encodedDataFile = fileWithData.getFile(); fileWithData.close(); this.setData(new InternalInputStream(encodedDataFile, true), FilterFlags.RAW_DATA); } }
private Set<String> getAllFilters(COSDocument document) { Set<String> res = new HashSet<>(); for (COSObject base : document.getObjects()) { if (base.getType() == COSObjType.COS_STREAM) { COSFilters baseFilters = ((COSStream) base.getDirectBase()).getFilters(); addFilters(res, baseFilters); } } return res; }
/** * Applies decryption filter to the stream so it can be read as unencrypted. * * @param stream is COSStream with encrypted data. * @param key is COSKey of this stream. */ public void decryptStream(COSStream stream, COSKey key) throws IOException, GeneralSecurityException { ASInputStream encStream = stream.getData(); ASInputStream filter; if (isRC4Decryption) { filter = new COSFilterRC4DecryptionDefault(encStream, key, this.encryptionKey); } else { filter = new COSFilterAESDecryptionDefault(encStream, key, this.encryptionKey, true, method); } document.addFileResource(new ASFileStreamCloser(filter)); stream.setData(filter, COSStream.FilterFlags.RAW_DATA); }
COSKey key = trueTypeFontFile.getObjectKey(); boolean isSymbolic = this.isSymbolic(); COSObject encoding = this.getEncoding(); this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = trueTypeFontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new TrueTypeFontProgram(fontData, isSymbolic, encoding); this.fontProgram = StaticResources.getCachedFont(fontProgramID); if (fontProgram == null) { try (ASInputStream fontData = trueTypeFontFile.getData(COSStream.FilterFlags.DECODE)) { this.fontProgram = new OpenTypeFontProgram(fontData, false, isSymbolic, encoding, null, isSubset);