mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-15 12:05:03 +00:00
31 lines
1010 B
Java
31 lines
1010 B
Java
![]() |
package stirling.software.SPDF.service;
|
||
|
import org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction;
|
||
|
|
||
|
import stirling.software.SPDF.service.CustomPDFDocumentFactory;
|
||
|
import stirling.software.SPDF.service.PdfMetadataService;
|
||
|
|
||
|
class SpyPDFDocumentFactory extends CustomPDFDocumentFactory {
|
||
|
enum StrategyType {
|
||
|
MEMORY_ONLY, MIXED, TEMP_FILE
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
}
|