MemoryLimitsAwareHandler implements Serializable { public boolean isMemoryLimitsAwarenessRequiredOnDecompression(PdfArray filters) { final HashSet<PdfName> filterSet = new HashSet<>(); for (int index = 0; index < filters.size(); index++) { final PdfName filterName = filters.getAsName(index); if (!filterSet.add(filterName)) { return true; } } return false; } MemoryLimitsAwareHandler();  MemoryLimitsAwareHandler(long documentSize); int getMaxSizeOfSingleDecompressedPdfStream(); MemoryLimitsAwareHandler setMaxSizeOfSingleDecompressedPdfStream(int maxSizeOfSingleDecompressedPdfStream); long getMaxSizeOfDecompressedPdfStreamsSum(); MemoryLimitsAwareHandler setMaxSizeOfDecompressedPdfStreamsSum(long maxSizeOfDecompressedPdfStreamsSum); boolean isMemoryLimitsAwarenessRequiredOnDecompression(PdfArray filters);  }
@Test public void overridenMemoryHandler() { MemoryLimitsAwareHandler defaultHandler = new MemoryLimitsAwareHandler(); MemoryLimitsAwareHandler customHandler = new MemoryLimitsAwareHandler() { @Override public boolean isMemoryLimitsAwarenessRequiredOnDecompression(PdfArray filters) { return true; } }; PdfArray filters = new PdfArray(); filters.add(PdfName.FlateDecode); Assert.assertFalse(defaultHandler.isMemoryLimitsAwarenessRequiredOnDecompression(filters)); Assert.assertTrue(customHandler.isMemoryLimitsAwarenessRequiredOnDecompression(filters)); }