2025-05-19 14:12:06 +01:00
|
|
|
package stirling.software.SPDF.service;
|
|
|
|
|
2025-05-20 12:02:10 +01:00
|
|
|
import org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction;
|
2025-05-19 14:12:06 +01:00
|
|
|
|
|
|
|
class SpyPDFDocumentFactory extends CustomPDFDocumentFactory {
|
2025-05-20 12:02:10 +01:00
|
|
|
enum StrategyType {
|
|
|
|
MEMORY_ONLY,
|
|
|
|
MIXED,
|
|
|
|
TEMP_FILE
|
|
|
|
}
|
|
|
|
|
2025-05-19 14:12:06 +01:00
|
|
|
public StrategyType lastStrategyUsed;
|
|
|
|
|
|
|
|
public SpyPDFDocumentFactory(PdfMetadataService service) {
|
|
|
|
super(service);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StreamCacheCreateFunction getStreamCacheFunction(long contentSize) {
|
|
|
|
StrategyType type;
|
|
|
|
if (contentSize < 10 * 1024 * 1024) {
|
|
|
|
type = StrategyType.MEMORY_ONLY;
|
|
|
|
} else if (contentSize < 50 * 1024 * 1024) {
|
|
|
|
type = StrategyType.MIXED;
|
|
|
|
} else {
|
|
|
|
type = StrategyType.TEMP_FILE;
|
|
|
|
}
|
|
|
|
this.lastStrategyUsed = type;
|
|
|
|
return super.getStreamCacheFunction(contentSize); // delegate to real behavior
|
|
|
|
}
|
2025-05-20 12:02:10 +01:00
|
|
|
}
|