@Test public void embeddedFileIsCompressed() throws Exception { victim = ReadOnlyFilteredCOSStream.readOnlyEmbeddedFile(StreamSource.newInstance(stream, "chuck")); assertThat(victim.getFilteredStream(), instanceOf(DeflaterInputStream.class)); }
public static final ReadOnlyFilteredCOSStream readOnlyEmbeddedFile(Source<?> source) throws TaskIOException { COSDictionary dictionary = new COSDictionary(); dictionary.setItem(COSName.FILTER, COSName.FLATE_DECODE); return source.dispatch(new SourceDispatcher<ReadOnlyFilteredCOSStream>() { @Override public ReadOnlyFilteredCOSStream dispatch(FileSource source) throws TaskIOException { try { ReadOnlyFilteredCOSStream retVal = new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(new FileInputStream(source.getSource())), -1); retVal.setEmbeddedInt(COSName.PARAMS.getName(), COSName.SIZE, source.getSource().length()); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(source.getSource().lastModified()); retVal.setEmbeddedDate(COSName.PARAMS.getName(), COSName.MOD_DATE, calendar); return retVal; } catch (FileNotFoundException e) { throw new TaskIOException(e); } } @Override public ReadOnlyFilteredCOSStream dispatch(StreamSource source) { return new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(source.getSource()), -1); } }); }
ReadOnlyFilteredCOSStream extends COSStream { public static final ReadOnlyFilteredCOSStream readOnlyEmbeddedFile(Source<?> source) throws TaskIOException { COSDictionary dictionary = new COSDictionary(); dictionary.setItem(COSName.FILTER, COSName.FLATE_DECODE); return source.dispatch(new SourceDispatcher<ReadOnlyFilteredCOSStream>() { @Override public ReadOnlyFilteredCOSStream dispatch(FileSource source) throws TaskIOException { try { ReadOnlyFilteredCOSStream retVal = new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(new FileInputStream(source.getSource())), -1); retVal.setEmbeddedInt(COSName.PARAMS.getName(), COSName.SIZE, source.getSource().length()); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(source.getSource().lastModified()); retVal.setEmbeddedDate(COSName.PARAMS.getName(), COSName.MOD_DATE, calendar); return retVal; } catch (FileNotFoundException e) { throw new TaskIOException(e); } } @Override public ReadOnlyFilteredCOSStream dispatch(StreamSource source) { return new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(source.getSource()), -1); } }); } }
ReadOnlyFilteredCOSStream extends COSStream { public static final ReadOnlyFilteredCOSStream readOnlyEmbeddedFile(Source<?> source) throws TaskIOException { COSDictionary dictionary = new COSDictionary(); dictionary.setItem(COSName.FILTER, COSName.FLATE_DECODE); return source.dispatch(new SourceDispatcher<ReadOnlyFilteredCOSStream>() { @Override public ReadOnlyFilteredCOSStream dispatch(FileSource source) throws TaskIOException { try { ReadOnlyFilteredCOSStream retVal = new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(new FileInputStream(source.getSource())), -1); retVal.setEmbeddedInt(COSName.PARAMS.getName(), COSName.SIZE, source.getSource().length()); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(source.getSource().lastModified()); retVal.setEmbeddedDate(COSName.PARAMS.getName(), COSName.MOD_DATE, calendar); return retVal; } catch (FileNotFoundException e) { throw new TaskIOException(e); } } @Override public ReadOnlyFilteredCOSStream dispatch(StreamSource source) { return new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(source.getSource()), -1); } }); } ReadOnlyFilteredCOSStream(COSDictionary existingDictionary, InputStream stream, long length);  ReadOnlyFilteredCOSStream(COSDictionary existingDictionary, InputStreamSupplier<InputStream> stream,
            long length); }
ReadOnlyFilteredCOSStream extends COSStream { public static final ReadOnlyFilteredCOSStream readOnlyEmbeddedFile(Source<?> source) throws TaskIOException { COSDictionary dictionary = new COSDictionary(); dictionary.setItem(COSName.FILTER, COSName.FLATE_DECODE); return source.dispatch(new SourceDispatcher<ReadOnlyFilteredCOSStream>() { @Override public ReadOnlyFilteredCOSStream dispatch(FileSource source) throws TaskIOException { try { ReadOnlyFilteredCOSStream retVal = new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(new FileInputStream(source.getSource())), -1); retVal.setEmbeddedInt(COSName.PARAMS.getName(), COSName.SIZE, source.getSource().length()); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(source.getSource().lastModified()); retVal.setEmbeddedDate(COSName.PARAMS.getName(), COSName.MOD_DATE, calendar); return retVal; } catch (FileNotFoundException e) { throw new TaskIOException(e); } } @Override public ReadOnlyFilteredCOSStream dispatch(StreamSource source) { return new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(source.getSource()), -1); } }); } ReadOnlyFilteredCOSStream(COSDictionary existingDictionary, InputStream stream, long length);  ReadOnlyFilteredCOSStream(COSDictionary existingDictionary, InputStreamSupplier<InputStream> stream,
            long length); @Override long getFilteredLength(); @Override long getUnfilteredLength(); @Override InputStream getUnfilteredStream(); @Override SeekableSource getUnfilteredSource(); @Override OutputStream createFilteredStream(); @Override OutputStream createFilteredStream(COSBase filters); @Override void setFilters(COSBase filters); @Override boolean addCompression(); @Override boolean encryptable(); @Override void encryptable(boolean encryptable); @Override OutputStream createUnfilteredStream(); @Override boolean isEmpty(); @Override boolean indirectLength(); @Override void indirectLength(boolean indirectLength); @Override IndirectCOSObjectIdentifier id(); @Override void idIfAbsent(IndirectCOSObjectIdentifier id); @Override void close(); static ReadOnlyFilteredCOSStream readOnly(COSStream existing); static ReadOnlyFilteredCOSStream readOnlyJpegImage(File imageFile, int width, int height,
            int bitsPerComponent, PDColorSpace colorSpace); static final ReadOnlyFilteredCOSStream readOnlyEmbeddedFile(Source<?> source); }
ReadOnlyFilteredCOSStream extends COSStream { public static final ReadOnlyFilteredCOSStream readOnlyEmbeddedFile(Source<?> source) throws TaskIOException { COSDictionary dictionary = new COSDictionary(); dictionary.setItem(COSName.FILTER, COSName.FLATE_DECODE); return source.dispatch(new SourceDispatcher<ReadOnlyFilteredCOSStream>() { @Override public ReadOnlyFilteredCOSStream dispatch(FileSource source) throws TaskIOException { try { ReadOnlyFilteredCOSStream retVal = new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(new FileInputStream(source.getSource())), -1); retVal.setEmbeddedInt(COSName.PARAMS.getName(), COSName.SIZE, source.getSource().length()); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(source.getSource().lastModified()); retVal.setEmbeddedDate(COSName.PARAMS.getName(), COSName.MOD_DATE, calendar); return retVal; } catch (FileNotFoundException e) { throw new TaskIOException(e); } } @Override public ReadOnlyFilteredCOSStream dispatch(StreamSource source) { return new ReadOnlyFilteredCOSStream(dictionary, new DeflaterInputStream(source.getSource()), -1); } }); } ReadOnlyFilteredCOSStream(COSDictionary existingDictionary, InputStream stream, long length);  ReadOnlyFilteredCOSStream(COSDictionary existingDictionary, InputStreamSupplier<InputStream> stream,
            long length); @Override long getFilteredLength(); @Override long getUnfilteredLength(); @Override InputStream getUnfilteredStream(); @Override SeekableSource getUnfilteredSource(); @Override OutputStream createFilteredStream(); @Override OutputStream createFilteredStream(COSBase filters); @Override void setFilters(COSBase filters); @Override boolean addCompression(); @Override boolean encryptable(); @Override void encryptable(boolean encryptable); @Override OutputStream createUnfilteredStream(); @Override boolean isEmpty(); @Override boolean indirectLength(); @Override void indirectLength(boolean indirectLength); @Override IndirectCOSObjectIdentifier id(); @Override void idIfAbsent(IndirectCOSObjectIdentifier id); @Override void close(); static ReadOnlyFilteredCOSStream readOnly(COSStream existing); static ReadOnlyFilteredCOSStream readOnlyJpegImage(File imageFile, int width, int height,
            int bitsPerComponent, PDColorSpace colorSpace); static final ReadOnlyFilteredCOSStream readOnlyEmbeddedFile(Source<?> source);  }